Page 1 of 1

rich (HTML) area never empty

Posted: 2019-10-27 22:50
by baudwalker
Hi all,

I have text feild set as a "Rich (HTML) area". I wish to only show the content of this feild if it is not empty, but as this type of feild always has and entry of "<br>" at a minimum so it is never empty. A text feild set as a "Text area" can be empty.

Is there a way to have am empty "Rich (HTML) area"

Barry

Re: rich (HTML) area never empty

Posted: 2019-10-28 12:20
by pbottcher
Hi,

this is the default behaviour of nicEdit.

Either you edit the nicEdit.js and replace
this.setContent("<br />")
by
this.setContent("")
or you can use

Code: Select all

$j('.nicEdit-main').html('');
to clear the <br> when it is set at the beginning.

For the first option you need to keep in mind that this may be overwritten if you regenerate your project.
The second option may be a little bit more tricky, as you may need to check first if the nicEdit is already present and then check if it contains only the "<br>" and then replace it.

Re: rich (HTML) area never empty

Posted: 2019-10-29 03:47
by baudwalker
Great... Thank you

Re: rich (HTML) area never empty

Posted: 2019-10-29 06:24
by jsetzer
Additionally, if you need to remove <br> before saving to have an empty value in the database table, you can do a simple serverside replacement of <br> in hooks/TABLENAME_before_insert() and hooks/TABLENAME_before_update() hook like this:

Code: Select all

// file: hooks/TABLENAME.php

// ...

function TABLENAME_before_insert(&$data, $memberInfo, &$args){
    if ($data['FIELDNAME']=='<br>') $data['FIELDNAME']=null;
    return TRUE;
}

function TABLENAME_before_update(&$data, $memberInfo, &$args){
    if ($data['FIELDNAME']=='<br>') $data['FIELDNAME']=null;
    return TRUE;
}

// ...