Skip to content Skip to sidebar Skip to footer

How To Configure A Parsley Custom Remote Using Javascript, Not Attributes

Similarly to this question and this question I can't figure out how to How to configure a Parsley custom remote using Javascript, when binding an individual field. e.g. I'm trying

Solution 1:

It turns out it was the value of the remote option needs to be "remote" not true.

$('#field').parsley({
    remote: 'remote',
    remoteValidator: 'mycustom';
});

As there is no attribute value for data-parsely-remote, I'd guessed "presence of tag" would evaluate to true, not the last word of the dashed attribute.

Solution 2:

When you define your validateString(value, url, options, instance), the options you will receive are the options of the remote validator. This validator is defined with:

  requirementType: {
    '': 'string',
    'validator': 'string',
    'reverse': 'boolean',
    'options': 'object'
  },

So there will be a validator option ('mycustom'), possibly a reverse option, and also possible a options option.

So you could bind your field with:

$('#field').parsley({
    remote: true,
    remoteValidator: 'mycustom',
    hello: 'world',
    remoteOptions: { foo: 'bar' }
});

and access 'bar' within your validator with options.options.foo or instance.options.remoteOptions.foo, and get 'world' with instance.options.hello.

Post a Comment for "How To Configure A Parsley Custom Remote Using Javascript, Not Attributes"