in reply to Re^6: Converting hash into js object properties
in thread Converting hash into js object properties

The outputted keys need to be barewords, I believe.

Ah, I see, I misread your post here and I thought you were talking about the extra quotes in the values, not the keys. Yes, the quotes around the keys are required by JSON, but JSON is a subset of JavaScript, so if someone is requiring you to omit the quotes, I'd ask why that is and why they can't accept regular JSON.

  • Comment on Re^7: Converting hash into js object properties

Replies are listed 'Best First'.
Re^8: Converting hash into js object properties
by nysus (Parson) on Nov 21, 2017 at 17:04 UTC

    OK, so adding double quotes to the jQuery directly didn't break anything, the validator script still works with them. So I guess I'm good to go. Thanks!

    $PM = "Perl Monk's";
    $MCF = "Most Clueless Friar Abbot Bishop Pontiff Deacon Curate";
    $nysus = $PM . ' ' . $MCF;
    Click here if you love Perl Monks

      adding double quotes to the jQuery directly didn't break anything

      jQuery is "just" a library, in that way it is similar to, for example, Moo: it just makes good/clever use of existing language syntax to provide an interface that makes it look like it's adding new syntax to the language (e.g. jQuery's $(...), Moo's has), but it is in fact working within the confines of the language (other modules can be added to provide sugar). The same way one can write regular Perl subs into Moo classes and use everything that Perl has to offer, one can use all of vanilla JavaScript when working with jQuery.

        Thanks.

        I have run into a bit of a roadblock. If a value is set to some jQuery code (let's say to get the value of a text field), it surrounds the jQuery code with quotes which does break things. Can you think of any good ways around this problem?

        $PM = "Perl Monk's";
        $MCF = "Most Clueless Friar Abbot Bishop Pontiff Deacon Curate";
        $nysus = $PM . ' ' . $MCF;
        Click here if you love Perl Monks

Re^8: Converting hash into js object properties
by nysus (Parson) on Nov 21, 2017 at 16:57 UTC

    Ok, this is for the jquery validation module and is being used inside of a jquery call like so:

    $("#myform").validate({ rules: { contact: { required: true, email: { depends: function(element) { return $("#contactform_email").is(":checked"); } } } } });

    So, I'm not familiar enough with jQuery to know if adding the double quotes will break things or not. I guess I could try and see what happens.

    $PM = "Perl Monk's";
    $MCF = "Most Clueless Friar Abbot Bishop Pontiff Deacon Curate";
    $nysus = $PM . ' ' . $MCF;
    Click here if you love Perl Monks