• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

[SCRIPTING] Verify if all is checked (edittext, radiobutton, checkbox)

Enthusiast ,
Aug 31, 2020 Aug 31, 2020

Copy link to clipboard

Copied

Hello, all.

I'm working on script where some panels are managed dinamically by the user or based on selection. I mean I'm using for loops to add children to the panel.

I want to know how can I check if, for example:

- At least one of the radiobuttons are selected

- At least one of the checkboxes are checked

- All edittext fields are filled with some text

 

Of course I don't have all those cases at once.

Hope I was clear on what I need.

Thanks in advance.

TOPICS
Scripting

Views

255

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Participant , Aug 31, 2020 Aug 31, 2020

hi, you can put all objects in an array and check them as you want, for example:

function check_list(list,flag){
	var rez = []
	for(var i = 0; i < list.length; i++){
		switch(flag){
			case 'radiobutton':
			case 'checkbox':
				if(list[i].value){rez.push(true)}
				break;
			case 'edittext':
				if(list[i].text != ''){rez.push(true)}
				break;
		}
	}
	switch(flag){
		case 'radiobutton':
		case 'checkbox':
			if(rez.length != 0){return true}
			break;
		case 'edittext':
			if(rez.length == list.
...

Votes

Translate

Translate
Participant ,
Aug 31, 2020 Aug 31, 2020

Copy link to clipboard

Copied

hi, you can put all objects in an array and check them as you want, for example:

function check_list(list,flag){
	var rez = []
	for(var i = 0; i < list.length; i++){
		switch(flag){
			case 'radiobutton':
			case 'checkbox':
				if(list[i].value){rez.push(true)}
				break;
			case 'edittext':
				if(list[i].text != ''){rez.push(true)}
				break;
		}
	}
	switch(flag){
		case 'radiobutton':
		case 'checkbox':
			if(rez.length != 0){return true}
			break;
		case 'edittext':
			if(rez.length == list.length){return true}
			break;
	}
	return false
}

mylist = []
mylist.push(children)
...
check_list(mylist,'element type')

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Sep 01, 2020 Sep 01, 2020

Copy link to clipboard

Copied

LATEST

Thank you so much, @SychevKA. It worked pretty well!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Aug 31, 2020 Aug 31, 2020

Copy link to clipboard

Copied

the message was duplicated and cannot be deleted, so I edited it

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines