Evaluate undefined for a field
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?
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 Kozlov
- Site Admin
- Posts: 1524
- Joined: Thu Jun 07, 2012
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://spform.com/forms-designer- ... eld-values
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.
!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
- Site Admin
- Posts: 1524
- Joined: Thu Jun 07, 2012
Hi,
You can check whether the Enhanced Rich Text field is empty following way:
You can check whether the Enhanced Rich Text field is empty following way:
Code: Select all
if (!fd.field('RTE').control()._el().find('div.ms-rtestate-write').text().trim()) {
alert('RTE field is empty');
}
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.
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
- Site Admin
- Posts: 1524
- Joined: Thu Jun 07, 2012
trim() function removes all spaces, tabs, and newlines from the beginning and end of strings. You can try the following function instead:
It removes all non-printable characters from the string.
Code: Select all
fd.field('RTE').control()._el().find('div.ms-rtestate-write').text().replace(/\W/g, '')
-
- Information
-
Who is online
Users browsing this forum: No registered users and 1 guest