How to use required validation on editor.dependent (show) function
How to use required validation on editor.dependent (show) function

HI,
I am new to Datatables and have spent a couple of days trying to find the solution without making any head way. So please forgive me if this is a newbie question.
In the insert\edit function i have 2 fields that only appears when one specific value on other field is selected:
editor.dependent( 'p2b_users.naccessusers', function ( val ) {
return val === '1' ?
{ show: ['p2b_users.supervisor_id','p2b_users.sfid'] } :
{ hide: [] }; } );
I´m trying to use the required\notEmpty function, but if i use this way i'm not allowed to submit the form even without triggering the editor.dependent (show) event.
Field::inst( 'p2b_users.sfid' )
->validator( Validate::required() )
->validator( Validate::numeric() )
->validator( Validate::unique(ValidateOptions::inst()
->message('SFID já atribuído.')
))
Is it possible to use the required validator ONLY if those fields where visible triggered by the editor.dependent (show) event?
Can someone help me please?
Thank you very much.
Replies
Hi,
Yes, but it requires a little change to how your server-side code works. Basically you want to conditionally add the validation for those optional fields. If the value is such that it needs the validation, only then would you add them.
That can be done with server-side events. In this case the
preEdit
andpreCreate
events are the two you want to listen for.Inside the function add the validation e.g.:
Regards,
Allan
Hi Colin,
Thank you for your help. Already applied and functional. Simple as shared.
Regards,
João
Hi Allan,
After all, I couldn't get it to work on my project.
I can get it up and running if I don't use leftjoin, but unfortunately I do.
I don't know where I went wrong ... as soon as I add the leftjoin and it stops working giving the following error on submit:
PHP:
JS:
Can anyone help?
Project link:http://tlmk.qualportal.com/testes/
Regards,
João
Hi,
Problem solved.
Line 2 was wrong,I was not setting the value correctly.
Case closed.
Thanks for the help Allan.
Regards,
João
Glad all sorted, thanks for reporting back,
Colin