Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
    Hock
    @martianmartian
    ohh. hold on let me try
    Hock
    @martianmartian
    so i added the ui and included in the code
    there's a new error
    (intermediate value).add_field is not a function
    for this line of code .add_field("name", new FVTextField("Name"))
    Marcus Longmuir
    @MarcusLongmuir
    Post the whole block
    Hock
    @martianmartian
    you mean my code?

    <!DOCTYPE html>

    <html>
    <head>
    <title></title>
    <script src="./javascripts/fieldval.js"></script>
    <script src="http://code.jquery.com/jquery-1.11.1.js"></script>
    <script src="./javascripts/fieldval-ui.min.js"></script>
    </head>
    <body>

    </body>
    </html>

    <script type="text/javascript">

    $(document).ready(function(){

    var output = $("<pre/>");
    var display_output = function(value) {
    output.text("Form output:\n" + JSON.stringify(value, null, 4));
    }

    var form = new FieldVal()
    .add_field("name", new FVTextField("Name"))
    .add_field("email", new FVTextField("Email"))
    .add_field("subscribe", new FVBooleanField("Subscribe?"))
    .on_submit(function(value){
    display_output(value);
    })

    form.element.append(
    $("<button/>").text("Submit")
    ).appendTo("body");

    var value = {
    name: "Name",
    email: "Email",
    subscribe: true
    }
    form.val(value);
    display_output(value);
    output.appendTo("body");
    });

    </script>

    Marcus Longmuir
    @MarcusLongmuir

    This line:
    var form = new FieldVal()

    should be:
    var form = new FVForm()

    Hock
    @martianmartian
    oh right, i tried to read the fieldval.js without ui, and changed the function to the wrong name..
    nice it's working!!
    Marcus Longmuir
    @MarcusLongmuir
    Great :D
    Hock
    @martianmartian
    i think i will be able to go on my own from here. thank you so much!
    my name is xiao qu btw, nice "meeting" you Marcus!
    Marcus Longmuir
    @MarcusLongmuir
    You too Xiao. Good luck
    Hock
    @martianmartian
    Thanks!
    Hock
    @martianmartian
    i figure it out
    Alexander Maslov
    @drakmail
    Hi all!
    Could I validate values through AJAX? Like validation of unique user name/email address?
    Stanislavs Beguns
    @bestan
    @drakmail hello! sure, that sounds like something we’re doing very often
    Alexander Maslov
    @drakmail
    But I doesn't found anything in documentation about it =/
    Stanislavs Beguns
    @bestan
    could you please explain your use case a little bit further so I could give an example or the right direction?
    Alexander Maslov
    @drakmail
    example of validation function:
    function(field) {
      $.getJSON("/field/validate", {field: field}, function(data) {
        // check results
        // I must run callback here? But validation function doesn't accepts callbacks..
      });
      return undefined; // ???
    }
    Stanislavs Beguns
    @bestan
    yea, you want async validation, which already exists, but we haven’t got a chance to document it
    give me a moment
    Alexander Maslov
    @drakmail
    Cool! Seems, it will be my favorite validation library :yellow_heart:
    Stanislavs Beguns
    @bestan

    okay, so when you’re calling validator.get - you need to change it to validator.get_async:

    validator.get_async(“field_name”, [BasicVal.string(), check2, check3…])

    note that checks are in an array now (docs will cover why it has to be an array and not regular chaining)

    the check function under async shoud now looke like

    function(value, emit, callback)

    callback takes an error as a first argument or null/undefined if there are no errors

    finally, validator.end should be async as well

    validator.end(function(error) {
        //error == null if everything is good
    })
    full example can look like this
    var validator = new FieldVal(params);
    validator.get_async("field", [BasicVal.string(), function(value, emit, callback) {
        setTimeout(function() {
            var error = null;
            // var error = {error:1234};
            callback(error);
        }, 50);
    }])
    
    validator.get("other_field", BasicVal.string());
    
    validator.end(function(error) {
        console.log(error);
    })
    just uncomment the // var error = {error:1234} to see how the error changes when calling .end(callback)
    we’re in the process of documenting it, but until we’re finished I’m more than happy to help you out on this :)
    Alexander Maslov
    @drakmail
    Thanks! It is what I need. Will try to change old ugly custom validation code with FieldVal in soon weeks.
    Stanislavs Beguns
    @bestan
    Great! Let us know if you have any questions ;)
    Stanislavs Beguns
    @bestan
    @/all we’ve just posted a new blog post to HackerNews. Check out “Most API Errors Suck” on https://news.ycombinator.com/newest and don’t forget to upvote :+1:
    blueglassbottle
    @blueglassbottle
    is there anywhere to find documentation on the error codes that are coming out of Fieldval?
    Stanislavs Beguns
    @bestan
    @blueglassbottle hey, check http://www.fieldval.com/docs/fieldval/Errors
    blueglassbottle
    @blueglassbottle
    thanks @bestan I checked that out but I don't understand what the different assignments are like error 5 vs error 107
    that doesn't seem to be in the documentation so I don't if they are assigned at random or what?
    Stanislavs Beguns
    @bestan
    when inspecting an error object you would normally see an error_message there too
    107 is just
    {
        error: 107,
        error_message: "Invalid email address format.”
    }
    the convention is that FieldVal errors start from error code 1, BasicVal (check functions) start at 100, and your custom error codes should start from 1000 (to avoid conflicting with FieldVal and BasicVal error codes)
    blueglassbottle
    @blueglassbottle
    ah, that makes sense! Thank you for the clarification. Great library btw
    thanks @bestan
    Stanislavs Beguns
    @bestan
    any time :)
    Stanislavs Beguns
    @bestan
    @/all we’ve just posted "Asynchronous Data Validation with FieldVal.js" blog post to HackerNews. Support us by upvoting here: https://news.ycombinator.com/newest
    Stanislavs Beguns
    @bestan
    @/all FieldVal is now on MinoHubs. Check it out! https://www.minohubs.com/hub/fieldval/
    thatspassion
    @thatspassion

    Is there any way i can overwrite the default ie. "Field missing." error_messages? I tried with...

    var my_error = {
    error: 1001,
    error_message: "ABCD"
    }

    validator.get("mytest", bval.string(true, {
    error: my_error
    }), bval.min_length(3));

    ... and with validator.error("mytest"){
    error: 1020,
    error_message: "ABCD"
    });

    ..but first didn't worked and last gives me only a additional error.

    Btw. great work, hope to master it soon! ^^

    Marcus Longmuir
    @MarcusLongmuir

    Hey @thatspassion.

    You can use missing_error here:

    validator.get("mytest", bval.string(true, {
    missing_error: my_error
    }), bval.min_length(3));

    I need to get round to documenting some of these more obscure usages. Good luck with the library. I hope it's useful.

    thatspassion
    @thatspassion
    Hey Marcus! Thanks for your answer. I did a fieldVal UI Form and played around to get the validation perfect with customized error messages. I thought its the convenient way. But if you call it obscure i maybe have to ask a better way. :) ...and for sure your lib is useful! Best regards, Martin
    Marcus Longmuir
    @MarcusLongmuir
    @thatspassion: it's actually not that obscure compared to some other things. Don't worry :smile: