Using Dependent API to change editor form fields throws "Uncaught SyntaxError:Unextected token '.'"
Using Dependent API to change editor form fields throws "Uncaught SyntaxError:Unextected token '.'"
I am trying to get Dependent API working by setting fields in an Editor form based on changes in another field. The only examples I can find simply refers to show/hide but nothing about setting values.
editor.dependent( 't_laundryOrder.ordLoc', function ( val ) {
return val === '1' ?
{ editor.field( 't_laundryOrder.ordDate' ).val( '2022-01-01') } :
{ editor.field( 't_laundryOrder.ordDate' ).val( '2022-02-01') };
} );
Line three throws this error in console
Uncaught SyntaxError: Unexpected token '.'
I got close to making this work by using this example which simply looks at it from a change function. However this was merely to see if there was user interation on the field or not and then resetting the field. Perhaps if I could know what condition to make the change occur instead of '!d || !d.editor'
$( editor.field( 't_laundryOrder.ordLoc' ).input() ).on( 'change', function (e, d) {
if ( ! d || ! d.editor ) {
editor.field( 't_laundryOrder.ordDate' ).val( 0);
editor.field( 't_laundryOrder.ordDate' ).val( '');
}
} );
Surely there is an easy solution? Eventually I want to be able to change Select field options based on the options in another Select field (I gather that is best done via a JSON response?). But solving the above will do for now.
This question has an accepted answers - jump to answer
Answers
Your first example is close - instead of returning that, you just need to set it. This example here should help, it's change the salary field if the office is set to "XXX".
Colin
Awesome! Thanks Colin. That worked well. I would appreciate how to update a select field would be helpful. (Data extrated using sql or JSON source)
This example updates a
select
field in theinitEdit
, but you could do that update from a trigger independent()
instead - the principle would be the same,Colin