Question

I have a collapsible (enter your credit card info) form. When I click it it opens, but when I click submit I want it to close. Here's my html:

<div class= "addStuff">
<div data-role="collapsible" data-inset="true" id="ccdiv">
   <h5> New credit card</h5>         
      <div data-role="fieldcontain">
            <form id = "myForm">
        <input type="password" name="credit_card_number" id="credit_card_number" value="" placeholder="Credit Card Number">
        <input type="password" name="security_code" id="security_code" value="" placeholder="Security Code">
        <input type="date" name="expiration_date" id="expiration_date" value="" placeholder="Expiration Date">
        <input type="password" name="name" id="name" value="" placeholder="Name On Card">
        <input type="password" name="street_address" id="street_address" value="" placeholder="Street Address">
        <input type="text" name="city" id="city" value="" placeholder="City">
        <input type="number" name="zip_code" id="zip_code" value="" placeholder="Zip Code">

            <button type="button" class="submit" name="submit" value="submit">Submit</button>
            </form>
      </div>
</div>

And here is my JS attempt:

$(document).ready(function() {
$('.submit').click(function(){
    var creditcard = $('#credit_card_number').val();
    $('.accounts #CreditCards div[data-role="content"] #swipeMe').append('<li data-swipeurl="#" ><a href="#">' + creditcard + '</a></li>');
   // refresh view 
   $('#CreditCards ul').listview('refresh');

   // hide form
 alert('test'); 


 $('#myForm').slideUp();
 $('#myForm').trigger('collapse');

    });
});
Était-ce utile?

La solution

Here is a link to a JsFiddle I worked on to try and get your code working http://jsfiddle.net/rvqRX/

I went thru line by line and commented each one out one at a time and found that the only line I had to comment out for it to behave correctly was this

$('#CreditCards ul').listview('refresh');

Not sure why... does it make any sense to you?

Autres conseils

On submit() of form, make sure your trigger to collapse the form is called using JQuery method . Is that what you are looking for?

Add an ID to your form <form id="myForm">...</form>

Collapse your form where you want using a JQuery animation :

$('#myForm').slideUp();
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top