Highlighted

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

Enthusiast ,
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.

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')

 

TOPICS
Scripting

Views

59

Likes

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

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

Enthusiast ,
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.

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')

 

TOPICS
Scripting

Views

60

Likes

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
Aug 31, 2020 0
Participant ,
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')

 

Likes

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
Reply
Loading...
Aug 31, 2020 1
Enthusiast ,
Sep 01, 2020

Copy link to clipboard

Copied

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

Likes

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
Reply
Loading...
Sep 01, 2020 0
Participant ,
Aug 31, 2020

Copy link to clipboard

Copied

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

Likes

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
Reply
Loading...
Aug 31, 2020 1