Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remote and depends bug #431

Closed
devantoine opened this issue May 21, 2012 · 16 comments
Closed

Remote and depends bug #431

devantoine opened this issue May 21, 2012 · 16 comments
Labels

Comments

@devantoine
Copy link

When you try to remote with depends, the AJAX's parameters are not taken.
The simple test case below illustrates it:

$('#field').rules('add', {
  required: true,
  remote: {
    depends: function(el) {
      return $(el).val() != loginValue;
    },
    url: 'myurl',
    type: 'POST'
  },
  messages: {
    remote: "fail"
  }
});

The call is made via GET to the page's url, not in POST to 'myurl'.

@shakerlxxv
Copy link

I also encountered this issue, it's not a new thing as I see posts referencing the same scenario from at least 3 years ago.

I did find a very acceptable workaround, but I'd rather not use it if the underlying code is possibly going to be "fixed" which would likely break this solution. The workaround I found is to nest the standard remote: properties under a property named param:. If the depends: function returns true, it will reference the properties as you would expect.

Here's a sinippet of what my rule ends up looking like:

        rules: {
          'appointment_type[name]': {
            required: true,
            remote: {
              param: {
                url: "/hw/validate/appointment_type/name.json",
                data: {
                  'appointment_type[id]': "5"
                }
              },
              depends: function() {
                return $("#appointment_type_name").val() !== "Adjustment2";
              }
            }
          },

As far as I can tell this is a 100% solution to the issue, with the only downside being the possibility future versions of the validation plugin would change this behavior.

@devantoine
Copy link
Author

Wow, this is a nice workaround, I'll try it as soon as possible, thanks!

Edit: this is working like a charm.

@paganotoni
Copy link

Thanks, thats working cool!

@arkson82
Copy link

Hey thanks! Awesome workaround.

@timmaybrown
Copy link

Awesome! Just what I needed.

@krnbr
Copy link

krnbr commented Oct 16, 2013

awesome

@jzaefferer
Copy link
Collaborator

As far as I can tell, this is a documentation issue. I've created #981 to keep track of that.

@Pazout
Copy link

Pazout commented Mar 28, 2014

Hey thanks!

@egiw
Copy link

egiw commented Jun 11, 2014

It works perfectly!

@tsango1972
Copy link

Hi there. Any idea if this solution is still valid because it doesn't seem to call the AJAX/Remote code when the url is placed within the param.

@sjosen
Copy link

sjosen commented Oct 21, 2014

Works for me. Thx

@ecorona
Copy link

ecorona commented Nov 12, 2014

Thank you very much!

@unifreak
Copy link

Solved my headache. Thank you :)

@jackDing2016
Copy link

Works!

@arya-choudhury
Copy link

Thank you @shakerlxxv it helped me a lot

@maheshd1991
Copy link

param data: attribute will not dynamically set. it will set only while when document is ready.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests