Allows updating field options / values on another field(s) update.
To refer to repeater field, write inner repeater field in square braces, like [text_field1]
.
This example requires JetEngine to be installed; otherwise, custom options Generator should be created - see Advanced section.
Works for Select, Radio, Checkboxes fields
See https://jetformbuilder.com/features/multi-optional-field-source-settings/ to set up a field using Get values list from JetEngine Query generator
$_REQUEST['jfb_update_related_' . $field_name]
, e.g. $_REQUEST['jfb_update_related_select1']
to update options accordingly. In this example, in the field 'select2' we get posts, related to post selected in the field 'select1'Also, there is a macro \ \ JFB Update Field - Form Field Value that you can use,
and a source for Relation macros \ \ added by this addon.
We set Related Items macro to get initial object ID from jfb_update_related_select1, so that when we choose the post in the field 'select1', 'select2' will be populated with posts, related to post from the field 'select1'
Don't forget to set a fallback, so that up until selection in 'select1' there will be no posts in 'select2'
Alternatively, use JFB Update Field - Form Field Value macro to do the same: \
This example requires JetEngine to be installed; otherwise, use custom callback - see Advanced section
Works for Text, Textarea, Hidden fields
242|post_title - 242 is an ID of the query you will use, post_title is a parameter that will be retrieved from the first query item.
Like in Updating field options example, we use jfb_update_related_select1 variable. Don't forget to set a fallback too.
https://github.com/ihslimn/jet-forms-generate-from-posts-query example of registering a generator. Form field values are stored into $_REQUEST['jfb_update_related_' . $field_name]
To update field value with a custom callback, register a function, for example:
function jfbu_get_post_date( $field_name, $form_id, $form_fields ) {
if ( $form_id !== 28447 || $field_name !== 'text_field' || empty( $form_fields['select1'] ) ) {
return;
}
$post = get_post( $form_fields['select1'] );
if ( ! $post ) {
return;
}
return $post->post_date;
}
and use it in options