Page 1 of 1
Empty Multiple lines of text (Enhanced rich text)
Posted: 22 Feb 2018
by cmagnan
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
Re: Empty Multiple lines of text (Enhanced rich text)
Posted: 22 Feb 2018
by Nikita Kurguzov
Dear Catherine,
Try this instead:
Code: Select all
if($(fd.field('Multiline').value()).text().length > 1){
alert("Has text");
}
Re: Empty Multiple lines of text (Enhanced rich text)
Posted: 22 Feb 2018
by cmagnan
Hi Nikita,
It is not working.
I have also changed the sign to less than instead of greater then.
Re: Empty Multiple lines of text (Enhanced rich text)
Posted: 22 Feb 2018
by Nikita Kurguzov
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");
}
Re: Empty Multiple lines of text (Enhanced rich text)
Posted: 22 Feb 2018
by cmagnan
Now it is working
Thank you very much
Re: Empty Multiple lines of text (Enhanced rich text)
Posted: 22 Feb 2018
by cmagnan
Finally it is not working. How I can validate if user forget to add something in the field
Re: Empty Multiple lines of text (Enhanced rich text)
Posted: 26 Feb 2018
by Nikita Kurguzov
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?
Re: Empty Multiple lines of text (Enhanced rich text)
Posted: 27 Feb 2018
by cmagnan
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");
}
});
Re: Empty Multiple lines of text (Enhanced rich text)
Posted: 27 Feb 2018
by Nikita Kurguzov
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;
}