This is a migrated thread and some comments may be shown as answers.

[RadInputManager/C#] Property, total validations failed

6 Answers 88 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Michiel Peeters
Top achievements
Rank 1
Michiel Peeters asked on 21 Sep 2010, 09:22 AM
Dear Telerik Community,

Is there for the radinputmanager an property where i can ask if validations are failed? Can this property also be obtained via javascript? I have searched for many places but i am not able to find an answer on it :)

Kind regards,
Michiel Peeters

6 Answers, 1 is accepted

Sort by
0
Michiel Peeters
Top achievements
Rank 1
answered on 21 Sep 2010, 09:33 AM
Additional information:

In the hurry i have forgot the code snippit where i want it to achive:

// Intakes the object
function IntakeObject() {
     
    var rangeId = $("input[id *= 'hfRangeId']").attr("value");
    var projectId = $("input[id *= 'hfProjectId']").attr("value");
    var objectTypeId = $("input[id *= 'hfObjectTypeId']").attr("value");
    var serviceId = $("input[id *= 'tbServiceId']").attr("value");
 
    var objectValues = new Object();
 
    $("input[id *= 'dynamicFieldControl'").each(function () {
        var fieldId = $(this).attr("ID").split("-")[1];
        var value = $(this).attr("value");
 
        objectValues[fieldId] = value;
    })
 
    IntakeObjectHandler.IntakeObject(rangeId, projectId, objectTypeId, serviceId, objectValues, SuccesMethod, FailureMethod, null);
}

This code snippit is called in the javascript function and no postback will take place, so radinputmanager cannot stop the user to intake a object. So if need a validation something like that: radInputManager.TotalValidationsFailed > 0 then give the user an warning, when the total validations failed is 0 then save the object.
0
Maria Ilieva
Telerik team
answered on 24 Sep 2010, 01:56 PM
Hi Michiel,

Give this suggestion a try and let me know if it helps

I would suggest you to handle the OnError event and set the needed flag for verifying the validation with it. Please refer to the following help topic which elaborates on this RadInputManager event. 

Kind regards,
Maria Ilieva
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Michiel Peeters
Top achievements
Rank 1
answered on 29 Sep 2010, 12:49 PM
Dear Maria,

Thank you for the response and a apoligize from my side that i react this late, but i have created an workaround which also suits my needs. I have an another question about the radinputmanager (its about the RegExpTextBoxSetting but that implemented in the radinputmanager). Currently my form is dynamicly loaded from the code behind which works perfectly fine, only there is one problem which i cannot resolve. This issue is about the RegExpTextBoxSetting (like i said before) and espacially about the ValidationExpression. In an another thread of me they have answered to obtain the latest version of the telerik controls, which i did. In this version (when leaving the RegExpTextBoxSetting empty) it should hold my data without erasing it but it doesn't. It erases my data which i don't want. The following code snippit is the most latest version of the dynamic rendering of the controls. My question is what am i doing wrong with the validationexpressions?

I have two validationexpressions: the first is a numeric validation expression which may only contain [0-9]. It can happen that the user provides a minimal length of the numeric textbox so i set it like this {1,} for example. When i put here {0,} it throws an exception in the javascript. So i want to leave that last part out so that it accepts [0-9] but it doesnt need to meet the minimal length. For the text validation expression i only use the minlength but when i leave my validationexpression blank it just throws my textbox empty, which i don't want.

I have stripped out parts which are not needed for the explanation of my problem:
Text Validation
private TextBox textualControl(ServiceObjectFieldDefinition fieldDefinition, RadInputManager inputManager)
{
    string controlId = string.Format("dynamicFieldControl-{0}", fieldDefinition.Id);
    this.dynamicDefaultKeys.Add(controlId);
 
    RegExpTextBoxSetting textualValidationSetting = new RegExpTextBoxSetting();
    textualValidationSetting.BehaviorID = string.Format("TextualBehavior{0}", fieldDefinition.Id);
    textualValidationSetting.EnabledCssClass = string.Format("{0} data-entry", textualValidationSetting.EnabledCssClass);
    textualValidationSetting.FocusedCssClass = string.Format("{0} data-entry", textualValidationSetting.FocusedCssClass);
    textualValidationSetting.InvalidCssClass = string.Format("{0} data-entry", textualValidationSetting.InvalidCssClass);
    textualValidationSetting.HoveredCssClass = string.Format("{0} data-entry", textualValidationSetting.HoveredCssClass);
 
    TextBox textualTextbox = new TextBox();
    textualTextbox.ID = controlId;
 
    textualValidationSetting.ValidationExpression = "";
    if (fieldDefinition.Mandatory)
    {
        textualValidationSetting.Validation.IsRequired = true;
        textualTextbox.ID = string.Format("{0}_required", textualTextbox.ID);
    }
    if (fieldDefinition.MaxLength != null)
        textualTextbox.MaxLength = Convert.ToInt32(fieldDefinition.MaxLength);
    if (fieldDefinition.MinLength != null)
        textualValidationSetting.ValidationExpression = string.Format("{0}{{1},}", textualValidationSetting.ValidationExpression, Convert.ToInt32(fieldDefinition.MinLength));
    if (!string.IsNullOrEmpty(fieldDefinition.DefaultValue))
        textualTextbox.Text = fieldDefinition.DefaultValue;
    if (fieldDefinition.DefaultValueFixed)
        textualTextbox.Enabled = false;
    if (fieldDefinition.MinLength != null)
        textualValidationSetting.ValidationExpression = string.Format("{{0},}", Convert.ToInt32(fieldDefinition.MinLength));
 
    this.dynamicDefaultValues.Add(fieldDefinition.DefaultValue);
 
    TargetInput textualValidationInput = new TargetInput(textualTextbox.ID, fieldDefinition.DefaultValueFixed ? false : true);
    textualValidationSetting.TargetControls.Add(textualValidationInput);
 
    inputManager.InputSettings.Add(textualValidationSetting);
 
    return textualTextbox;
}

Numeric Validation
private TextBox numericControl(ServiceObjectFieldDefinition fieldDefinition, RadInputManager inputManager)
{
    string controlId = string.Format("dynamicFieldControl-{0}", fieldDefinition.Id);
    this.dynamicDefaultKeys.Add(controlId);
 
    RegExpTextBoxSetting numericValidationSetting = new RegExpTextBoxSetting();
    numericValidationSetting.BehaviorID = string.Format("NumericBehavior{0}", fieldDefinition.Id);
    numericValidationSetting.EnabledCssClass = string.Format("{0} data-entry", numericValidationSetting.EnabledCssClass);
    numericValidationSetting.FocusedCssClass = string.Format("{0} data-entry", numericValidationSetting.FocusedCssClass);
    numericValidationSetting.InvalidCssClass = string.Format("{0} data-entry", numericValidationSetting.InvalidCssClass);
    numericValidationSetting.HoveredCssClass = string.Format("{0} data-entry", numericValidationSetting.HoveredCssClass);
 
    TextBox numericTextbox = new TextBox();
    numericTextbox.ID = controlId;
 
    if (fieldDefinition.Mandatory)
    {
        numericValidationSetting.Validation.IsRequired = true;
        numericTextbox.ID = string.Format("{0}_required", numericTextbox.ID);
    }
 
    numericValidationSetting.ValidationExpression = "[0-9]";
    if (fieldDefinition.MaxLength != null)
        numericTextbox.MaxLength = Convert.ToInt32(fieldDefinition.MaxLength);
    if (fieldDefinition.MinLength != null)
        numericValidationSetting.ValidationExpression = string.Format("{0}{{1},}", numericValidationSetting.ValidationExpression, Convert.ToInt32(fieldDefinition.MinLength));
    if (!string.IsNullOrEmpty(fieldDefinition.DefaultValue))
        numericTextbox.Text = fieldDefinition.DefaultValue;
    if (fieldDefinition.DefaultValueFixed)
        numericTextbox.Enabled = false;
 
    this.dynamicDefaultValues.Add(fieldDefinition.DefaultValue);
 
    TargetInput numericValidationInput = new TargetInput(numericTextbox.ID, fieldDefinition.DefaultValueFixed ? false : true);
    numericValidationSetting.TargetControls.Add(numericValidationInput);
 
    inputManager.InputSettings.Add(numericValidationSetting);
 
    return numericTextbox;
}

Further details:

Visual Studio 2010 Professional
Telerik Controls 2010.2.826.40 (Latest)
0
Michiel Peeters
Top achievements
Rank 1
answered on 01 Oct 2010, 08:12 AM
Dear Telerik Community,

Recently i posted an message with the question why my validations still doesn't work. Finally i managed to make the validations work but i ran into an another problem. My problem occurs when i fill in an textbox and hit the enter key (i have a enter to tab javascript function) it goes to the next textbox. During this step to the next textbox it will validate my input based on the following code snippits:

function isFieldFilledIn(obj) {
    if (obj.type == "checkbox") {
        return true;
    }
 
    if (obj.id.indexOf("_Input") > 0) {
        if (obj.value != "" && obj.value.length > 0) {
            return true;
        }
        else {
            return false
        }
    }
 
    var rimControl = $find("<%= rimIntakeObjects.ClientID %>");
    rimControl._onSubmit();
 
    var inputSettings = rimControl.get_inputSettings();
 
    for (behaviorKey in inputSettings) {
        if (inputSettings[behaviorKey]._targetControlIDs[0] == obj.id) {
            if (inputSettings[behaviorKey]._isRequired) {
                if (inputSettings[behaviorKey]._radInputExtender.get_value() != "" && inputSettings[behaviorKey]._radInputExtender.get_value().length > 0)
                    return true;
                else
                    return false;
            }
            else {
                return true;
            }
        }
    }
}

And

function isFieldValid(obj) {
    if (obj.type == "checkbox") {
        return true;
    }
 
    if (obj.id.indexOf("_Input") > 0) {
        if (obj.value != "" && obj.value.length > 0) {
            return true;
        }
        else {
            return false
        }
    }
 
    var rimControl = $find("<%= rimIntakeObjects.ClientID %>");
    rimControl._onSubmit();
 
    var inputSettings = rimControl.get_inputSettings();
 
    for (behaviorKey in inputSettings) {
        if (inputSettings[behaviorKey]._targetControlIDs[0] == obj.id) {
            if (obj.id.indexOf("dateControl") > 0) {
                if (inputSettings[behaviorKey]._radInputExtender.isNegative())
                    return false;
                else
                    return true;
            }
            else {
                if (inputSettings[behaviorKey]._radInputExtender.isValid())
                    return true;
                else
                    return false;
            }
        }
    }
}

And it failes my focus will remain in the textbox where i just entered some random data. Surprisingly my text is also gone! When i debug my javascript code it tells me that the originalvalue is filled in but my originalvalue is not filled in back into the textbox (so that someone knows that they have made an mistake). I have also included an picture where my problem is explained.

I hope you guys of the telerik community can reply to me a.s.p. because i need to finish this piece of code. Btw, people can also use the above code snippits to validate their input clientside :) (my complete page functions clientside).

Yours faithfully,

Michiel Peeters
0
Maria Ilieva
Telerik team
answered on 01 Oct 2010, 09:07 AM
Hi Michiel,

As the provided information is not enough to isolate the root cause of the issue you are facing, please prepare a simple, fully runnable reproduction demo, open a new support ticket and send it to us along with very detailed reproduction steps and explanations and we will debug it locally and we will do our best to help.

Greetings,
Maria Ilieva
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Michiel Peeters
Top achievements
Rank 1
answered on 01 Oct 2010, 11:28 AM
Dear Maria,

As you suggested have i created an support ticket.

Yours faithfully,
Michiel Peeters
Tags
General Discussions
Asked by
Michiel Peeters
Top achievements
Rank 1
Answers by
Michiel Peeters
Top achievements
Rank 1
Maria Ilieva
Telerik team
Share this question
or