Ticket T214361
Visible to All Users

dxTextBox validation problem - How to dynamically assign validation rules

created 10 years ago (modified 10 years ago)

Hi,

We developed a mobile application using DevExtreme "knockout-3.1.0.js", "knockout.validation.js" and  " jquery-2.1.1.min.js" its working fine, after updating "knockout-3.2.0.js" and  " jquery-2.1.3.min.js", its not working.

Here is working code with old version:

JavaScript
var self = this; result += "<div class='dx-field'>"; result += " <div class='dx-field-label'>" + data[i].fieldName + ": </div>"; //result += " <div class='dx-field-value' id='Custom" + i + "' style='width:100px;margin-right:100px;'></div>"; result += " <div class='dx-field-value' id='Custom" + i + "'></div>"; result += "</div>"; $("#customFieldArea").append(result); if (eval(data[i].requiredField) == true) { var Custom0 = ko.observable().extend({ required: 'Please enter value.' }); self.Custom0 = Custom0; $("#Custom" + i).dxTextBox({ placeholder: "Enter Text", value: Custom0, }); } else { $("#Custom" + i).dxTextBox({ placeholder: "Enter Text", }); } var validationModel = ko.validatedObservable(self); if (validationModel.isValid()) { // create event } else { // Alert }

The above code is not working any more in new upgrade.

We are trying implement using your example validtaions. Its not working. Can you please give working examples.

JavaScript
$("#Custom" + i).dxTextBox({ placeholder: "Enter Text", value: ko.observable(""), isValid: eventOptions.login1.dxValidator.isValid, validationError: eventOptions.login1.dxValidator.validationError, }); //}).dxValidator({ name: 'Name', validationRules: [{ type: 'required' }]}); } else { $("#Custom" + i).dxTextBox({ placeholder: "Enter Text", }); }

Thank you,
Subash

Comments (2)
DevExpress Support Team 10 years ago

    Hi Subash,

    I am afraid that the provided information is not sufficient to determine the cause of the problem. Your code is not complete and uses a third-party library. Would you please reproduce the issue in a simple project and send it to us for research? If it is not possible, please let us know. We will find another way to help you.

      Hi Uriah,
      Thank for your quick response.
      Its not easy to create a projects, we are creating dynamic controls.
      Make it simple, can you please create a dynamic dxTextBox control on fly and validate with required field  validation. That what I am trying to do.
      Thank you,
      Subash

      Answers approved by DevExpress Support

      created 10 years ago

      Hello Andrea,

      Here is a simple example demonstrating how to create a dxTextBox with the required validator on the fly with jQuery.
      http://jsfiddle.net/tabalinas/4z27wpy7/

        Comments (2)

          what if I already have a required validation and I want to add another validation ,e.g. email at runtime? also how can I remove the email validation at runtime and set another validation for the same dxTextBox?

          DevExpress Support Team 8 years ago

            Hello Jassim,

            I've created a separate ticket on your behalf (T536664: How to change dxTextBox validation rules at run-time). It has been placed in our processing queue and will be answered shortly.

            Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

            Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.