Required information

I have a window that has multiple text boxes on it. My users are entering information into those boxes or in some cases just selecting a toggle box. After that they click on a submit button to dump the information into a sql table I have created.

How can I make that submit button require all the other boxes to have information and/or be actually selected if they are a toggle button before the submit button will actually fire and dump the information?

Add expression binding to the Enable property of the submit button. For example, if you want text in a text box, the expression might be len({Root Container.Text Box.text}) > 0.
You can join multiple conditions together with logical operator (&&, ||, etc.).

1 Like

So what if it is a string tag or int. tag instead?

// Require either an entry in text box or integer entry field.
len({Root Container.Text Box.text}) > 0
|| {Root Container.IntEntry.value} > 0
// Add more conditions with and (&&) or or (||), grouping with parenthesis as needed.

Or if you mean a tag value, not a value from a component as shown above, your expression would use the tags, something like:

len({[default]stringTag}) > 0
|| {[default]intTag} > 0

I got the coding to work:

len({Root Container.AreaSelected.text}) > 0
&& ({Root Container.ShiftSelected.text}) > 0

but this does nto require both of them to be > 0. Right now when I select the shiftselected text box and enter info the submit button becomes visible, but not when I select the AreaSelected text box.

Try (note second len):

len({Root Container.AreaSelected.text}) > 0
&& len({Root Container.ShiftSelected.text}) > 0

Nope… that just makes the submit button back to displaying all the time… LOL

I actually tried the text box and the tag options and they both had the same outcomes… weird…

Works for me on 8.0.12:

Code in enabled property of button (as you posted above):

Hmmmm. I dont know. I have exactly what you have and it does not work. I am using version 7.9.13.

Oh well. I guess I try to figure something else out.

Thank you for all your help!! I sincerely appreciate you taking the time…

1 Like

Something else that is weird is that even if I uncheck the check box in the enable property I can actually still click on the submit button and it fire…

That is weird. If you’re doing all this in the Designer, maybe try restarting it. I also just verified the button in my example definitely won’t run the code I put in it when it is disabled. There is another issue with this method; the button doesn’t get enabled/disabled unless enter is pressed or mouse clicks elsewhere after entering/removing text in a field. This could be resolved by scripting focus on something else on mouse exit of the text fields.

A different method–and the one I’d generally use–would be to check for required values in the script that executes when you tap the button instead of disabling the button. If required values aren’t there, notify the user that they need to enter them. This would all be in the button’s actionPerformed event handler.

areaEntered = len(event.source.parent.getComponent('AreaSelected').text) > 0
shiftEntered = len(event.source.parent.getComponent('ShiftSelected').text) > 0
if areaEntered and shiftEntered:
	# Do something.
	# Notify user.

Here is my 2c.
You should create a custom property on each of the input components called something like ‘isValid’. Let each component decide what is valid and then combine these properties in a binding on your Submit button’s Enabled property.
There are numerous benefits to adding the properties onto the inputs rather than just validating them in the Submit button’s bindings.
The biggest benefit is that you can use the isValid property to affect the styling of the component, e.g. highlighting it with a colour if it’s invalid.