clear or reset input on submit

28 views
Skip to first unread message

Sky Richardson

unread,
Sep 26, 2018, 9:30:25 AM9/26/18
to intercooler-js
What is the best way to clear an input on submit?

ic-action can take JQuery methods so  I tried ic-action="val". However this only works with an argument i.e val:foo

BTW I am absolutely loving the intercooler-js library!


<input type="text" class="form-control" id="test" name="phoneNumber" value="">
<button ic-action="val" ic-target="#test">clear</button>



Sky Richardson

unread,
Sep 26, 2018, 9:50:54 AM9/26/18
to intercooler-js
Here is the html for the form. My objective is to not the single input form is cleared on submission. Currently the user needs to click on the 'Clear' button after clicking on 'Submit'

<form ic-post-to="add-phone.php" ic-target="#{{ address.recID }}-phone-numbers">
  <div class="input-group mt-3">
    <input type="hidden" name="propertyID" value="{{ address.recID }}">
    <input type="text" class="form-control" id="exampleInputText1" placeholder="Enter phone number" name="phoneNumber" value="">
    <div class="input-group-append">
      <button class="btn btn-outline-secondary" type="reset">Clear</button>
      <button class="btn btn-outline-secondary" type="submit">Submit</button>
    </div>
   </div>
</form>

Carson Gross

unread,
Sep 26, 2018, 11:16:08 AM9/26/18
to Sky Richardson, intercooler-js
Hi Sky,

It sounds like you want something like this on your form:

<form id='search-form' ... ic-on-success="$('#search-form').reset()">
  ...
</form>

Cheers,
Carson



--
You received this message because you are subscribed to the Google Groups "intercooler-js" group.
To unsubscribe from this group and stop receiving emails from it, send an email to intercooler-j...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Sky Richardson

unread,
Sep 27, 2018, 3:49:03 AM9/27/18
to intercooler-js
Makes sense Carson, 

I am the equivalent of a script kiddie with no experience with js,or JQuery. Any chance you could help me over this hump?

I have tried to implement your suggestion without success. After 10 variations I am at a dead end.

Here is at the test page

Here is the error:
TypeError: $('#add-phone-number').reset is not a function. (In '$('#add-phone-number').reset()', '$('#add-phone-number').reset' is undefined)

What am I doing wrong?

Anders Baumann

unread,
Sep 27, 2018, 4:19:20 AM9/27/18
to intercooler-js
Hi Sky.

form.reset() is a DOM element method (not one on the jQuery object). So try this instead:
$("#add-phone-number")[0].reset();

/Anders

Sky Richardson

unread,
Sep 27, 2018, 6:47:01 AM9/27/18
to baum...@gmail.com, interco...@googlegroups.com
Yep that worked. Thanks so much Anders
The test page has been updated with your fix.
Reply all
Reply to author
Forward
0 new messages