jQWidgets Forums

jQuery UI Widgets Forums Grid validateeverpresentrowwidgetvalue execute twice?

This topic contains 9 replies, has 4 voices, and was last updated by  SandBird 5 years, 6 months ago.

Viewing 10 posts - 1 through 10 (of 10 total)
  • Author

  • KK
    Participant

    Please refer to this example: http://jsfiddle.net/vkLvyn69/4/

    Just modified your demo: demos/jqxgrid/everpresentrowvalidation.htm
    From:
    return { message: “Entered value should be more than 5 characters”, result: false };
    To:
    alert(“error”);
    return false;

    And I’ll get the alert twice (validateeverpresentrowwidgetvalue triggered twice)

    By the way, what is => return { message: “Entered value should be more than 5 characters”, result: false }; ? Looks like return this object doesn’t do anything?


    Peter Stoev
    Keymaster

    Hi KK,

    It is called as many times as it is necessary for validation of All editors in the row. It could be called more than once of course.

    Best Regards,
    Peter Stoev

    jQWidgets Team
    http://www.jqwidgets.com


    KK
    Participant

    I’m talking about the validation on the same ‘Name’ column will be executed more than once, not a general validation for all editors in the row.
    Error alert for invalid data entered in ‘Name’ column will be shown multiple times when you try to add a row of data.


    Peter Stoev
    Keymaster

    Hi KK,

    And the answer is the same.

    Best Regards,
    Peter Stoev

    jQWidgets Team
    http://www.jqwidgets.com


    suall936
    Participant

    Hi Peter,

    May I ask why the validation function is called twice? According to your reply, it is to validate all editors in the row, does it mean there are 2 editors in the row? but there are 4 columns, all editable.

    Sorry to bring this old post up, but it is eating me up, I just can’t figure it out.

    Thank you


    Peter Stoev
    Keymaster

    Hi suall936,

    The function is called when necessary It does not matter how many times its called, just add your validation logic in it if your intentions are to use it. Otherwise, you can add own custom validation logic and do not use our validation functions.

    Best Regards,
    Peter Stoev

    jQWidgets Team
    http://www.jqwidgets.com


    suall936
    Participant

    Hi Peter,

    Thank you.

    Is it possible to access the error message raised in the validation function?

    return {message: “Entered value should be more than 5 characters”, result: false };


    Peter Stoev
    Keymaster

    Hi suall936,

    Why should you access it? You can change it by returning a different message depending on the column.

    Best Regards,
    Peter Stoev

    jQWidgets Team
    http://www.jqwidgets.com


    suall936
    Participant

    Hi Peter,

    Reason is the error message displays as tooltip (correct me if I’m wrong), if I can access the message I can put it in a warning panel or something similar.

    Regards.


    SandBird
    Participant

    Hello Peter,

    I apologize to revive this yet again but since I also encountered the same issue I wanted to ask about it.

    Following the examples on the site (and then some), I have the following validation check (simplified version):

    validateEverPresentRowWidgetValue: function (datafield, value) {
    					switch (datafield) {
    						case "name":
    							if (value.length == 0) {
    								message = "Name field must be bigger than 0 characters";
    							} else if (value.length > 45) {
    								message = "Name field must be smaller than 45 characters";
    							} else if (value.replace(/\s/g, "") === "") {
    								message = "Please enter a valid input";
    							} else {
    								$.ajax({
    									...some ajax code where variable uniqueValData
    									is assigned an appropriate value if entered value is unique.
    								});
    								if (uniqueValData !== 0) {
    									message = "This value already exists, please enter a unique value";
    								} else {
    									return true;
    								}
    							}
    							notification("error", message, "#dataGrid"); //built-in function to utilize jqxNotification
    							return { message: message, result: false };
    						break;
    					}
    					return true;
    				}

    The problem, as the previous users noted, is that this it runs twice on the same editor. In the case above the function will iterate twice for the “name” editor – I know this because I get two notification prompts.
    Shouldn’t the function run only once? or at least per the switch (datafield) it should only validate once for the “name” editor. Otherwise I see it goes twice also to the database to check (I see two same consecutive ajax calls) which I don’t see a reason to.

    You mentioned (in post #74421) that ” Otherwise, you can add own custom validation logic and do not use our validation functions.” I am unsure if you are referring to something else than the above and if so I would appreciate if you can please share or point to where I can see how to do that.

    Thank you for your time clearing the confusion about this.

Viewing 10 posts - 1 through 10 (of 10 total)

You must be logged in to reply to this topic.