0

I have just started learning JQuery validate and have come across an issue (no doubt it is of my own making) when I am trying to use the remote function.

The call to my action works and is hitting my API and returning the value I am expecting, I have also tested the output of the call in console.log() so I am happy that the call is being made and returning values.

The validation message is not appearing when the return value is true. True being that UniqueMappingRef exists, hence the error message saying such.

I have seen an answer, but this only seems to allow one remote function, when I will need an additional four to the one already in this question:

Currently no message appears at all.

The code is in the rules section and is called UniqueMappingRef.

    $("#ProjectPrepForm").validate({
        onkeyup: false,
        rules: {
            ProjectName: {
                required: true
            },
            UniqueMappingRef: {
                required: true,               
                remote: {
                    type: "POST",
                    url: "/ProjectPrep/CheckUniqueMappingRef/",
                    data: {
                        'internalRef': function () {
                            return $('#UniqueMappingRef').val()
                        }
                    },
                    success: function (d) {                        
                        if (d == true) {
                            messages:{
                                UniqueMappingRef: 'It already exists.'
                            }

                        }
                    },
                    error: function (request, status, errorThrown) {
                        alert(status);
                    }
                }
            }            
        },
        messages: {
            ProjectName: {
                required: 'Enter an project name'
            },
            UniqueMappingRef: {
                required: 'Enter a unique mapping reference'
            }               
        }
    });
});

Issue: Validation message is not being show for remote call, even though the API is returning the correct value.

Expected outcome: when true, validation message is shown, false the message disappears. Once I understand what I have done wrong, I will add a further four call for different elements.

Sparky
  • 98,165
  • 25
  • 199
  • 285
The OrangeGoblin
  • 764
  • 2
  • 7
  • 27
  • Do not tag-spam. The jQuery Validation Engine is not the same plugin and you should have stopped to figure out the correct tag when you saw there was two. Edited. – Sparky Jun 11 '19 at 13:59
  • Why are you saying it's spam.? – The OrangeGoblin Jun 11 '19 at 14:01
  • Tag-spam is when you use irrelevant tags on a question in order to attract more attention to it. When tagging, you saw that there was more than one tag for validation plugins for jQuery, so then that should have been a hint to figure out which tag was appropriate and not use both tags. – Sparky Jun 11 '19 at 14:59
  • And if you want help with the `remote` rule, it might be a good idea to show enough code to reproduce the issue. Show the relevant HTML markup and the server-side function. – Sparky Jun 11 '19 at 15:01
  • [Read the documentation for `remote` - nowhere in any of the examples are shown a validation message defined in the `success` ajax callback](https://jqueryvalidation.org/remote-method/). The plugin handles the message automatically based upon the response from the server-side code. You do not use the ajax for that part. – Sparky Jun 11 '19 at 15:05

0 Answers0