Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Probably way too late to answer this but here goes...</p> <p>The documentation for LiveValidation.remove states "you must pass it EXACTLY the same arguments as you used to add the validation". Although the validation function (Validate.Inclusion) is the same, the parameters object is going to be different each time. It doesn't matter that it "looks" the same (that is, the result should you to compare the value of every property between the object you added and the one you removed), it means that it <strong>has to be the same object</strong>. The only way to ensure this is to move the declaration of the parameters object <em>outside</em> the callback where you are manipulating the validation object, so that it is created only once and not every time the callback is called.</p> <p>Here's the code (I renamed your ids, BTW). I also made sure that the validation check could only be added once.</p> <pre><code>$(function() { var field12, added = false, stateList = ["", "AK", "CO", "WY"]; // etc params = { within: stateList, failureMessage: "Please enter a valid 2-letter state abbreviation." }; if ($('#state').length) { field12 = new LiveValidation('state', { validMessage: " ", onlyOnBlur: true }); field12.add(Validate.Presence, { failureMessage: "Please enter your state or province." }); } $('#country').change(function() { if ($("#country").val() == "United States") { if (!added) { field12.add(Validate.Inclusion, params); added = true; } } else { if (added) { field12.remove(Validate.Inclusion, params); added = false; } } }); }); </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload