Clear form input programmatically

I want to simulate the ‘input-clear-button’ programmatically - F7 uses the function clearInput but when I call that I get an error Cant find variable: clearInput.

Code is simply this:

function ResetAnswer() {
	clearInput();
}

@jmaynard, you could just use DOM7…

HTML:
<input type="text" id="sampleInput">

JS:
var $$ = Dom7;

$$('input#sampleInput').val(''); //set it to nothing any you're good to go..
2 Likes

Max
not sure I understand why but it works perfectly - thanks!

In my case, with a form like this:

<form
   class="list inset margin-std"
   style="background-color: white; padding-bottom: 0.5em;">
   <ul>
      <li class="item-content item-input">
         <div class="item-inner">
            <div class="item-input-wrap">
               <input
                  type="password"
                  placeholder="Ingrese Clave"
                  id="input_clave_autenticacion"
                  maxlength="50"
                  required
                  validate>
               <span class="input-clear-button"></span>
            </div>
         </div>
      </li>
   </ul>
</form>

I simulated the user clicked the button that clear input value with jquery:
$('.page[data-name="home"] #input_clave_autenticacion').next().trigger('click');

Result:
imagen

1 Like