Alpha DevCon 2018
Results 1 to 7 of 7

Thread: Field validation javascript in Formview not firing if value is null/undefined

  1. #1
    Member
    Real Name
    Doug Evenhouse
    Join Date
    Apr 2009
    Posts
    47

    Default Field validation javascript in Formview not firing if value is null/undefined

    Hi,

    I'm attempting to implement validation on a field in a Formview that ensures that the field is not empty or blank, i.e. it is required.

    However the validation javascript never fires unless there is a value in the field. At least that's the behavior I'm seeing. If I put a simple "alert('fired');" in the "Validation Javascript" property the alert never appears until after I put some value in the field. It appears that if the value in the field is null or undefined the code in the validation javascript property is never called. If I'm right about this, I can't use this property to make a field "required."

    How can I validate that a Formview field has a non-empty value?

    Thanks.

    Doug

  2. #2
    Member
    Real Name
    Doug Evenhouse
    Join Date
    Apr 2009
    Posts
    47

    Default Re: Field validation javascript in Formview not firing if value is null/undefined

    Also (related to validation) when the validation is fired and a validation error occurs it appears that the "formValueError" class is added to the DIV for the field on the Formview, but the error string returned by the validation javascript is injected after the field template (see attached screenshots).

    Is there a template placeholder that can be used for rendering/styling field validation error text?

    AATablet_formviewValidation.PNGAATablet_formviewValidation2.PNG

  3. #3
    "Certified" Alphaholic
    Real Name
    Govindan Gandhi
    Join Date
    Aug 2008
    Location
    New York, NY
    Posts
    4,294

    Default Re: Field validation javascript in Formview not firing if value is null/undefined

    How can I validate that a Formview field has a non-empty value?
    similar scenario was discussed in dialog/ux, i think in version 11 forum.
    for field validation to fire the field has to be embarked and disembarked. if the field is never visited then it won't fire. the only way to catch in that situation is in the dialog validate function before saving. since i do not have anything after version 11, i won't know where to tell you look for something similar in your version/component.
    thanks for reading

    gandhi

    version 11 3381 - 4096
    mysql backend
    http://www.alphawebprogramming.blogspot.com
    ggandhi344@gmail.com
    Skype:ggandhi344@gmail.com
    1 914 924 5171

  4. #4
    Member
    Real Name
    Doug Evenhouse
    Join Date
    Apr 2009
    Posts
    47

    Default Re: Field validation javascript in Formview not firing if value is null/undefined

    Quote Originally Posted by GGandhi View Post
    for field validation to fire the field has to be embarked and disembarked. if the field is never visited then it won't fire.
    The behavior I'm seeing with the Formview is that, for field validation logic to fire, the field must contain a non-null value, and the non-null value must be changed (become "dirty"). Therefore if the field contains an invalid value prior to visiting the field for input, it will not be checked for validity unless the user changes the value.

  5. #5
    Alpha Software Employee Beta Spark's Avatar
    Real Name
    Sarah Mitchell
    Join Date
    Jul 2015
    Posts
    399

    Default Re: Field validation javascript in Formview not firing if value is null/undefined

    Quote Originally Posted by dougeven View Post
    Also (related to validation) when the validation is fired and a validation error occurs it appears that the "formValueError" class is added to the DIV for the field on the Formview, but the error string returned by the validation javascript is injected after the field template (see attached screenshots).

    Is there a template placeholder that can be used for rendering/styling field validation error text?

    AATablet_formviewValidation.PNGAATablet_formviewValidation2.PNG
    Hi Doug!

    You could add styling to your field validation error text by wrapping your error message in HTML tags. EG:
    Code:
    var msg = "";
    if (v == 'Bob') msg = '<div class="errorMsg">Name cannot be Bob</div>';
    
    return msg;
    In the above validation javascript, I've wrapped the message, "Name cannot be Bob," inside a <div> element with the class name 'errorMsg'. In the CSS portion of the FormView, I added the definition for the errorMsg class:
    Code:
    .errorMsg {
        color: red;
        font-weight: bold;
        padding: 5px;
        margin: 2px;
        border: 2px solid blue;
    }
    And here's the result:
    formViewError_style2.png

    Let me know if you have any questions!
    Sarah Mitchell

    Looking for answers? Try our documentation.
    If you can't find something, let us know!

  6. #6
    Alpha Software Employee Beta Spark's Avatar
    Real Name
    Sarah Mitchell
    Join Date
    Jul 2015
    Posts
    399

    Default Re: Field validation javascript in Formview not firing if value is null/undefined

    Hello Doug!

    A place to define the CSS class used by the error text for a FormView control has been added:
    formProp1.png

    RE: Validation

    Functionality is being added to the FormView so you can validate all fields when data is committed. I'll post back when it becomes available.

    Thanks!
    Sarah Mitchell

    Looking for answers? Try our documentation.
    If you can't find something, let us know!

  7. #7
    Alpha Software Employee Beta Spark's Avatar
    Real Name
    Sarah Mitchell
    Join Date
    Jul 2015
    Posts
    399

    Default Re: Field validation javascript in Formview not firing if value is null/undefined

    Quote Originally Posted by dougeven View Post
    Hi,

    I'm attempting to implement validation on a field in a Formview that ensures that the field is not empty or blank, i.e. it is required.

    However the validation javascript never fires unless there is a value in the field. At least that's the behavior I'm seeing. If I put a simple "alert('fired');" in the "Validation Javascript" property the alert never appears until after I put some value in the field. It appears that if the value in the field is null or undefined the code in the validation javascript property is never called. If I'm right about this, I can't use this property to make a field "required."

    How can I validate that a Formview field has a non-empty value?

    Thanks.

    Doug
    Hi Doug!

    Thank you for bringing this to our attention. Validation on the FormView control now occurs when you try to save the form back to the original data source.

    If you have an existing FormView control with a Save button in the layout, you may need to either delete the Save button and add it again or modify the code for the click event for the button. Save buttons inserted into the FormView control layout will now contain this code:

    Code:
    var result = {dialog.object}.formViewValidate('{form.id}');
    if(result){
    	{dialog.object}.formViewCommit('{form.id}');
    	{dialog.object}.formViewRefresh('{form.id}');
    }
    Check the click event for your save button in your existing FormViews to make sure the new validation checks have been added.

    {dialog.object}.formViewValidate is a NEW function - it is available in Alpha Anywhere as of yesterday's build. I recommend installing the latest beta patch.

    If you have defined validation rules for fields in your FormView, they will be checked when the FormView is saved - even if the data in the field was not modified.

    In addition, there is a "Validate editor" event for Editors. You can add additional Validation code in this event.

    Let me know if you have any questions!

    Thanks!
    Sarah Mitchell

    Looking for answers? Try our documentation.
    If you can't find something, let us know!

Similar Threads

  1. Check for undefined field or variable in Javascript
    By JPMPA in forum Mobile & Browser Applications
    Replies: 0
    Last Post: 04-02-2014, 11:42 AM
  2. Check field validation in JavaScript
    By Scott B in forum Application Server Version 11 - Web/Browser Applications
    Replies: 0
    Last Post: 12-06-2013, 12:27 AM
  3. Javascript not firing on grid
    By lgrupido in forum Application Server Version 11 - Web/Browser Applications
    Replies: 4
    Last Post: 08-05-2013, 11:26 PM
  4. Unable to get value of the property 'bind': object is null or undefined
    By dmcgrew in forum Application Server Version 11 - Web/Browser Applications
    Replies: 4
    Last Post: 06-03-2013, 07:47 PM
  5. Unable to get value of the property 'length':object is null or undefined, When TabPan
    By satyanarayana in forum Application Server Version 11 - Web/Browser Applications
    Replies: 1
    Last Post: 12-11-2012, 02:44 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •