Is it possible to automatically reset a form field value back to default value when hidden?

Hi, I have the code (below) on my page, the default value for flour2 is zero. Is it possible (in wappler w/o using javascript) to automatically have form1.flour2.value reset back to zero when it is not shown?

<div class="form-group row" dmx-show="flourstomix.value >= 2">
                  <label for="flour2" class="col-sm-4 col-form-label">Second Flour %</label>
                  <div class="col-sm-3">
                    <input type="number" class="form-control" id="flour2" name="flour2" placeholder="Enter value" value="0" step="0.5" data-rule-min="0" data-rule-max="100" style="text-align: center;" dmx-on:change="form1.total.validate()" dmx-on:updated="form1.total.validate()">
                  </div>
                  <div class="col-sm-5">
                    <input type="text" class="form-control" id="flour2name" name="flour2name" placeholder="Flour Type Name" dmx-on:change="cookies1.set('secondflourname',value,{expires: 180})" dmx-bind:value="cookies1.data.secondflourname">
                  </div>
                </div>

Something like this (but this does not work, maybe a syntax problem?)

<div class="form-group row" dmx-show="flourstomix.value >= 2" "form1.flourstomix.value <= 2" ? form1.flour2.setValue(0)>
<div class="form-group row" dmx-show="flourstomix.value >= 2" "form1.flourstomix.value <= 2" ? form1.flour2.setValue(0)>

This will not work as the syntax is quite off.
Right now all this will do is only show when the flourstomix.value is greater than or equal to 2.

You can not set the actual input itself to be 0 when it is set to less than or equal to 2 as then the input will never get higher than 0.

Can you explain why or what you are wanting to achieve by this, what would happen differently if the value were 0.

Hi Paul, happy holidays to you, your friends and your family!!! Thanks for continuing to help me BTW.
I think I might have figured this out. Not tested yet but I have a good feeling. The problem is on my calculator if someone adds a value to any flour beyond the first one and then drops the number of flours to mix below that number the flour field is hidden and that number is stuck in the form and used in calculations. It is a big problem but I think the code below will fix. I fire the function “myStripFunction()” on a static event any time the number of flours to mix changes. If this works I will be amazed. Wish me luck!!!

function myStripFunction() {
  if (form1.flourstomix.value < 10) {
      (form1.flour10.value = 0);
      }
  if (form1.flourstomix.value < 9) {
      (form1.flour9.value = 0);
      }
    if (form1.flourstomix.value < 8) {
      (form1.flour8.value = 0);
      }
    if (form1.flourstomix.value < 7) {
      (form1.flour7.value = 0);
      }
    if (form1.flourstomix.value < 6) {
      (form1.flour6.value = 0);
      }
    if (form1.flourstomix.value < 5) {
      (form1.flour5.value = 0);
      }
    if (form1.flourstomix.value < 4) {
      (form1.flour4.value = 0);
      }
    if (form1.flourstomix.value < 3) {
      (form1.flour3.value = 0);
      }
    if (form1.flourstomix.value < 2) {
      (form1.flour2.value = 0);
      }
}
</script> 

Seems to work - I’m officially calling this an xmas miracle !

1 Like

Assume you are not having a Christmas turkey but rather a turkey topped pizza? :turkey::pizza:

1 Like

You can also set this value to 0 using the dynamic attributes.
dmx-bind:value="form1.flourstomix.value < 10 ? 0 : your_real_value_here"

1 Like

MERRY XMAS guys - for dinner I’m going to make a star pizza! Thanks for all the help this year and I hope all your wishes come true!!!

1 Like