Evaluate undefined for a field

rss

Posted by ChrisMBS - Apr 21 ’13 at 08:03

I'm trying to evaulate whether or not a multiline text field is blank.

I successfully used (fd.field('field name').control().value("")) for other text field. I did an alert on the field and it came back undefined.

What is the way to test for an empty multiline textbox in Forms Designer?

 

 

  • Dmitry
    Dmitry
    Admin
    Member for: 10 years 9 months 16 days
    #1 by Dmitry Apr 22 ’13 at 01:00

    There are 3 types of multiline text boxes in SharePoint: plain, rich and enhanced. You can read how to get/set values for them in our blog: http://formsdesigner.blogspot.ru/2013/04/getting-and-setting-sharepoint-form.html

  • JHMark
    Member
    Member for: 9 years 10 months 11 days
    #2 by JHMark Nov 10 ’14 at 04:13

    [#1]: But how do you test for empty field (the user skipped it)?  When empty, my Multiline Enhanced Rich Text Field returns a value of <p></p>, but when I test for a match on that value, it fails.

    !fd.field('addcomments').control()._el().find('div.ms-rtestate-write').html()

    does not work

    fd.field('addcomments').control()._el().find('div.ms-rtestate-write').html() == '<p> </p>'

    does not work

    I only need to know if there was no user input to this field.

     

  • Dmitry Kozlov
    Dmitry Kozlov
    Admin
    Member for: 9 years 6 months 5 days
    #3 by Dmitry Kozlov Nov 11 ’14 at 06:17

    [#2]: Hi,

    You can check whether the Enhanced Rich Text field is empty following way:

    if (!fd.field('RTE').control()._el().find('div.ms-rtestate-write').text().trim()) {
        alert('RTE field is empty');
    }
  • JHMark
    Member
    Member for: 9 years 10 months 11 days
    #4 by JHMark Nov 11 ’14 at 04:46

    [#3]: This almost works.

    What does  trim()  trim?

    If I tab through the Multiline Enhanced Rich Text Field, it leaves a non-printable character in there; something that trim() does not trim.  This also happens when the form is refreshed.  End result is that !fd.field('RTE').control()._el().find('div.ms-rtestate-write').text().trim() is not reliable because it returns "false" even when the field appears "empty".

    If I tab back into the field, click backspace or delete and then tab out, I get "true".  it seems to clear whatever "character" is hiding there.

  • Dmitry Kozlov
    Dmitry Kozlov
    Admin
    Member for: 9 years 6 months 5 days
    #5 by Dmitry Kozlov Nov 12 ’14 at 02:35

    [#4]: trim() function removes all spaces, tabs, and newlines from the beginning and end of strings. You can try the following function instead:

    fd.field('RTE').control()._el().find('div.ms-rtestate-write').text().replace(/\W/g, '')

    It removes all non-printable characters from the string.

  • JHMark
    Member
    Member for: 9 years 10 months 11 days
    #6 by JHMark Nov 12 ’14 at 03:45

    [#5]: That's the one!  Works perfectly, Thanks!

  • acquiro
    Member
    Member for: 2 years 10 months
    #7 by acquiro Jun 29 ’20 at 03:09
  • retrogress
    Member
    Member for: 2 years 1 month 25 days
    #8 by retrogress Jun 29 ’21 at 06:01

    I completely resolved my question when I read this post, thanks to the author for the very detailed description. I wrote my review on the novoresume review, you can go in and read. Thank you very much for your attention in your time.

  • peter0900
    Member
    Member for: 4 months 17 days
    #9 by peter0900 Mar 21 ’23 at 03:48

    Strictly speaking, the JavaScript value undefined is a basic type that evaluates to false in Boolean conditionals.

    Visit here https://businesscoachingservicesusa.com Business Coaching Services in USA

  • ahmedkhan
    Member
    Member for: 5 days
    #10 by ahmedkhan Mar 21 ’23 at 04:55

    Dawaguru is Pakistan’s leading online medical store that is the best choice for healthcare supplies. We provide the Gabica 75 mg capsule citizens so that they can receive the medicines at their doorstep. We bring a unique effective pharmacy that permits you to order easily. Our range of products includes cough & cold syrups, skin care medicated products, and allergy medicines that can quickly deliver to your doorstep.

Displaying 1 to 10 of 10 messages