Empty Multiple lines of text (Enhanced rich text)
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
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
- Nikita Kurguzov
- Posts: 889
- Joined: Mon Jul 03, 2017
Dear Catherine,
Try this instead:
Try this instead:
Code: Select all
if($(fd.field('Multiline').value()).text().length > 1){
alert("Has text");
}
Cheers
- Nikita Kurguzov
- Posts: 889
- Joined: Mon Jul 03, 2017
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:I have also changed the sign to less than instead of greater then.
Code: Select all
if($(fd.field('Multiline').value()).text().length <= 1){
alert("Has no text");
}
Cheers
- Nikita Kurguzov
- Posts: 889
- Joined: Mon Jul 03, 2017
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?
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
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");
}
});
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");
}
});
- Nikita Kurguzov
- Posts: 889
- Joined: Mon Jul 03, 2017
Dear Catherine,
This is a much harder task, but this code should work:
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
-
- Information
-
Who is online
Users browsing this forum: No registered users and 8 guests