0

I've dived into javascript & jquery for the first time and I'm having a little difficulty wrapping my head around a problem.

fieldedit.php

<div class="editinput-body">

    <form id="edit_field_form"  class="form-horizontal" action="field.php" method="post">
        <div class="form-group">
            <input type="text" maxlength="10" class="form-control" name="field_name" id="edit_field" value="" validFieldName/>
        </div>
    </form>

</div>
<div class="editinput-footer">
    <button type="button" class="btn btn-default" onclick="closeEdit()">Close</button>
    <button type="button" class="btn btn-primary" id="editsubmit" onclick="submitEdit()">Edit</button>
</div>

editvalidator.js

function submitEdit() 
{    
    var formValidator = $('#edit_field_form').validate();
    var success = false;

    try 
    {
        formValidator.addMethod("validFieldName", function (value, element) 
        {
            return false;
        }, jQuery.validator.format("INVALID."));

        success = formValidator.form();
    }
    catch(err) 
    {
        alert("Error\n\n" + err);
    }
}

The formValidator.addMethod throws the error "TypeError: Undefined is not a function".

I'm using jquery-1.9.1.min.js and jquery.validate.min.

Any help would be greatly appreciated.

Sparky
  • 98,165
  • 25
  • 199
  • 285
Ben Y
  • 291
  • 6
  • 14
  • You're doing way more work than you need to, working against the validation library. (And why are you doing inline JS with jQuery?) I don't know the source of your error, but you should be able to avoid it entirely by implementing Validator correctly. – Evan Davis Oct 13 '14 at 22:35
  • I need to be able to create my custom validation. Also, this is a project I'm just coming to work on towards its end. It is set up this way and I need to keep it as similar as possible. – Ben Y Oct 13 '14 at 22:36
  • Your code is not quite right. Just follow the examples [here](http://stackoverflow.com/a/241202/594235) and [here](http://stackoverflow.com/tags/jquery-validate/info). – Sparky Oct 14 '14 at 23:31

0 Answers0