Editor check whether field is hidden

Editor check whether field is hidden

rf1234rf1234 Posts: 2,943Questions: 87Answers: 416

I use this a lot with all kinds of editor fields:

editor.hide( ["predecessor[].prefixed_id"] );

Now I want to update the options of this field but only if it visible and wasn't programatically hidden.
I didn't find this visibility check in the api and had to code my own which was really cumbersome and looks like this

.....
if ( $('.' + $.escapeSelector('DTE_Field_Name_predecessor[].prefixed_id')).css('display') == 'none' ) {
    return;
}
editor.field('predecessor[].prefixed_id').update ( options, false );

Could you provide a method to do this with the api. Something like this would be great:

if ( editor.hidden( ["predecessor[].prefixed_id"] ) ) {
    return;
}

Replies

  • allanallan Posts: 63,200Questions: 1Answers: 10,414 Site admin
    edited December 2019

    Two ways to do it with the existing API:

    1) displayed() will list the currently displayed fields, so you could use:

    editor.displayed().indexOf('myFieldName') !== -1
    

    2) Or if you prefer a more DOM / jQuery method:

    $(editor.field().node()).is(':visible')
    

    Allan

  • rf1234rf1234 Posts: 2,943Questions: 87Answers: 416

    thanks, Allan!

    displayed() is precisely what I was looking for!
    Roland

This discussion has been closed.