I want the value of a text input to be null (cleared of any user input) when a checkbox becomes un-checked. I cannot figure out the exact expression to do this under the text input’s ‘Value’ dynamic attribute. Has anyone done this before, if so what is the expression you used?
Thank you
Hi!
I’m not quite sure, but i barely remember doing something in the past, with condition (in the server action), and two separates actions:
Example:
Have a checkbox ($_POST.inputC)
Have a text input ($_POST.inputT)
Have a insert1 action (With $_POST.inputT and other post variables)
Have a insert2 action (With the other post variables)
So:
Set the checkbox value to 1, and:
If $_POST.InputC == 1 then run Insert1, else run Insert2
PS: I remember trying to use page flow, reading checkbox value, run a condition, and set input text value to blank, but never work because it always posts blank.
Was something like that, i will try again, but maybe someone has a better way.
Is this what you are looking for?
<div class="form-check mb-3">
<input class="form-check-input" type="checkbox" value="thisValue" id="input1" name="input1">
<label class="form-check-label" for="input1">Default checkbox</label>
</div>
<input id="text1" name="text1" type="text" class="form-control" dmx-bind:value="input1.checked?input1.value:' '">
If your checkbox is named input1
then your text input dynamic value should be:
<input id="text1" name="text1" type="text" class="form-control" dmx-bind:value="!input1.checked ? '' : value">
This worked, thanks.
The picker part of this is completely broken, this expression must be entered by hand in the code window or it won’t work. See screen shots for what is happening.
Hoping this can be fixed so the expresssion can be entered via the picker.
You need to switch the expressions pickers to “code” mode in order to enter this expression. You can’t add it in the “design” mode.
In fact that’s what I originally did. Look at the resulting code it generates (in the actual form code screen shot) and you will see it is escaped with back slashes and this doesn’t work.
The user must enter code by hand or edit the code generated by the picker.
Again, the designer is broken.
This has been improved in Wappler 5.2.1. Now there are two new dynamic events for the checkboxes - checked and unchecked, so you can run different actions depending on the checkbox status.
Great news! Can’t wait to try this out!