Forums

Validation of hidden element

flashfs 25 Aug, 2017
I want to configure an element to be 'required' and hide that element. If some javascript shows the element, the 'required' would act, but if the element was still hidden, the 'required' would not act.

Is there a correct way to approach that on Chronoforms v6, or should I use javascript+PHP?
flashfs 28 Aug, 2017
I tried to hide and disable the field, but the Validate Fields on submit still tries do validate it any time.
flashfs 29 Aug, 2017
On Chronoforms 5, I could set an input as Required and, if I set the input to disabled, the required would not act after submit. On v6 this is not working, since the validation is always requiring the input, even if it is hidden/disabled. Is there a way to accomplish this on v6?
Max_admin 31 Aug, 2017
Hi flashfs,

The next update has a new validation "disabled" setting, this lets you set the validation requirements but keep it inactive until its enabled using a field event "Enable validation".

Best regards,
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
flashfs 31 Aug, 2017
Hey, Max, thanks for the response.
But what if I need to enable/disable the validation of an element based on some conditions inside a JS function? The Enable Validation inside the Events tab is a direct approach, but there are times where I do need to call a function first and that function will know if the validaiton should be enabled or not. What do you think?
flashfs 12 Sep, 2017
I've tested the 6.0.9 version and the new option to Disable the validation works just for the JavaScript. But after submiting the form, the action Validate Fields (the default one) is asking to fill the field, even if it is still with the Disable option checked.
Max_admin 29 Sep, 2017
Hi flashfs,

Apologies for the late reply!

I've tested the 6.0.9 version and the new option to Disable the validation works just for the JavaScript. But after submiting the form, the action Validate Fields (the default one) is asking to fill the field, even if it is still with the Disable option checked.


You will need to skip the disabled fields in the "Validate fields" action settings.

But what if I need to enable/disable the validation of an element based on some conditions inside a JS function? The Enable Validation inside the Events tab is a direct approach, but there are times where I do need to call a function first and that function will know if the validaiton should be enabled or not. What do you think?


Possible with a core change, if you still need this then let me know and I will tell you how to get it done.

Best regards,
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
flashfs 29 Sep, 2017

Possible with a core change, if you still need this then let me know and I will tell you how to get it done.


I don't like this approach because I don't like changing original code. But thanks.

You will need to skip the disabled fields in the "Validate fields" action settings.


I didn't see an option for that. Or do you mean manually writing the field name on the textbox? That would just disable the submit validation even if the field is enabled. I'm still trying to understand the most 'automatic' way to do that.
On v5 if a field was disabled, then it would automatticaly skip the submit validation. So I could write a JS function to enable/disable the field and that would do the trick, do you know?
Max_admin 03 Oct, 2017
Answer
Hi flashfs,

I didn't see an option for that. Or do you mean manually writing the field name on the textbox? That would just disable the submit validation even if the field is enabled. I'm still trying to understand the most 'automatic' way to do that.
On v5 if a field was disabled, then it would automatically skip the submit validation. So I could write a JS function to enable/disable the field and that would do the trick, do you know?


I get what you mean, the automatic processing can be added but it may take sometime, the current easy solution is to disable checking the field totally under the "Validate fields" action.

This way you disable the server validation, but the js validation is disabled easily using the events section of your field.

Best regards,
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
flashfs 03 Oct, 2017
Hmm, I see. Ok, I'll wait on that and work with it is current possible. Thanks.
HCH 10 Jan, 2019
Hello flashfs,

do you have a solution to your problem yet?

If yes: what is your solution?

I tested it with Chronoforms V. 6.0.19. And the problem is still available: if a entry field is configured as required and the entry field is hidden, then I cannont submit the form (like it was possible with CF5).

Regards,
Hans-Christian

healyhatman 11 Jan, 2019
If you're using field events to hide an element, then you also need to add "disable validation" if you want validation to pass when your hidden field is empty. This is not a "problem" this is how it's supposed to be.

healyhatman 11 Jan, 2019
If you need to programmatically remove validation from a field I suppose you could use
jQuery('.ui.form').form('remove field', 'fieldname');

And to programmatically add the validation back
jQuery('.ui.form').form('add fields', jQuery('.ui.form').form('get field', 'field_name'));
Although that second one is probably wrong.

https://semantic-ui.com/behaviors/form.html#/settings
This topic is locked and no more replies can be posted.