Drupal 9 unsetValue in an ajax callback
Budget: $30 – $250 USD
Field A = boolean
Field B = select list from a taxonomy entity
Field B = hidden, when field A is not select
Field C = checked, when Field B have certain values.
This is achieved with the #states
When Field A = unselect and Field B has value, this value remain in the form_state
Goal : unset the field value in an ajax callback.
if ($form_state->getValue('field_A') === 0 ) {
$form_state->unsetValue('field_B');
}
IF Field B have no value field C should be unchecked.
Not sure my approach is correct. Anny solution to unset the value is ok.
For clearness : Field A is a boolean, wether there is a nearby train station. When a user check this. Field B appear, where they can choose out of a distance. When the distance is 0 or 250m or 500m, field C is checked, that says, trainstation nearby.
Field B = select list from a taxonomy entity
Field B = hidden, when field A is not select
Field C = checked, when Field B have certain values.
This is achieved with the #states
When Field A = unselect and Field B has value, this value remain in the form_state
Goal : unset the field value in an ajax callback.
if ($form_state->getValue('field_A') === 0 ) {
$form_state->unsetValue('field_B');
}
IF Field B have no value field C should be unchecked.
Not sure my approach is correct. Anny solution to unset the value is ok.
For clearness : Field A is a boolean, wether there is a nearby train station. When a user check this. Field B appear, where they can choose out of a distance. When the distance is 0 or 250m or 500m, field C is checked, that says, trainstation nearby.