Empty Multiple lines of text (Enhanced rich text)

Discussions about Forms Designer for SharePoint 2013 / 2016 and Office 365.
Locked
cmagnan
Posts: 23
Joined: Fri Jan 26, 2018

22 Feb 2018

Hi,

I am trying to add an alert if a Multiple lines of text (Enhanced rich text) is empty.

I found these solutions in the forum but nothing work.

if ($(fd.field('FieldName').value()).text() == "")
if(!fd.field('FieldName').control()._el().find('div.ms-rtestate-write').text().replace(/\W/g, ''))

Can you help me
Catherine

User avatar
Nikita Kurguzov
Posts: 889
Joined: Mon Jul 03, 2017

22 Feb 2018

Dear Catherine,
Try this instead:

Code: Select all

if($(fd.field('Multiline').value()).text().length > 1){
    alert("Has text");
}
Cheers

cmagnan
Posts: 23
Joined: Fri Jan 26, 2018

22 Feb 2018

Hi Nikita,

It is not working.
I have also changed the sign to less than instead of greater then.

User avatar
Nikita Kurguzov
Posts: 889
Joined: Mon Jul 03, 2017

22 Feb 2018

I have also changed the sign to less than instead of greater then.
What do you mean? That wouldn't work as this condition will never be true. The problem is that there is always a non displayed symbol present, so the length is always going to be at least 1, but not less than 1. Try at least this:

Code: Select all

if($(fd.field('Multiline').value()).text().length <= 1){
    alert("Has no text");
}
Cheers

cmagnan
Posts: 23
Joined: Fri Jan 26, 2018

22 Feb 2018

Now it is working
Thank you very much

cmagnan
Posts: 23
Joined: Fri Jan 26, 2018

22 Feb 2018

Finally it is not working. How I can validate if user forget to add something in the field

User avatar
Nikita Kurguzov
Posts: 889
Joined: Mon Jul 03, 2017

26 Feb 2018

Dear Catherine,
What exactly is not working? Is it not checking the field correctly? Or do you want implement this functionality for saving an item, so you can check before save?
Cheers

cmagnan
Posts: 23
Joined: Fri Jan 26, 2018

27 Feb 2018

When I am using this code
If the value is empty, the field come with the red border and the alert is display correctly but if I am filling the field, the border is not remove.
How I can correct this?

var error = false;

function checkFields(){
error = false;
if($(fd.field('AnswerEnglish').value()).text().length <= 1){
setRedSingleERT('AnswerEnglish');
}
}

function setRedSingleERT(fieldname){
$('.fd_field[fd_name='+fieldname+'] .ms-inputBox').css(
{'border-color': 'rgb(171,29,0)'})
.change(function(){
var self = $(this);
if (self.text){
self.css(
{'border-color': ''})
}
});
error = true;
}

fd.onsubmit(function(){
checkFields();
if(!error){
return true;
}
else{
alert("The field is empty");
}
});

User avatar
Nikita Kurguzov
Posts: 889
Joined: Mon Jul 03, 2017

27 Feb 2018

Dear Catherine,
This is a much harder task, but this code should work:

Code: Select all

function setRedMultipleRich(fieldname){
	$('.fd_field[fd_name='+fieldname+'] .ms-inputBox').css(
        {'border-color': 'rgba(245,25,10,0.6)', 
        'box-shadow': '0px 0px 10px 0px rgba(245,5,90,0.8)'});
        fd.field(fieldname).change(function(){
  		if($(fd.field(fieldname).value()).text().length > 1){
            	    $('.fd_field[fd_name='+fieldname+'] .ms-inputBox').css(
                    {'border-color': '','box-shadow': ''});
            }	
         });
	 error = true;
}
Cheers

Locked
  • Information
  • Who is online

    Users browsing this forum: No registered users and 4 guests