Read Only Fields

4 posts by 3 authors in: Forums > CMS Builder
Last Post: December 2, 2013   (RSS)

Hey,

Is there an inbuilt function to set certain fields within a schema as read only?

I thought there was... but the System Field options and Admin Only doesn't achieve this - moreso just hides the fields altogether if non admin.

As well as setting some fields as read only, also want to disable the ability to amend the 'createdByUser' field.

Will do via a plugin if needbe, but wanted to see if I'm missing the existing functionality somewhere.

Cheers

Rob

By Dave - November 28, 2013

Hi Rob,

"System Field" just makes the field harder to accidently modify in the field editor (you need to turn on "Enable System Field Editing") from the Advanced Commands menu on the bottom left.

And you're right, "Admin Only" doesn't really do it either.

Probably the easiest would be to write a plugin that hooks in to 'record_presave' and if there's an $oldRecord to load it and overwrite select fields like this: 

if ($oldRecord) { 
  $_REQUEST['createdByUser'] = $oldRecord['createdByUser];
  $_REQUEST['etc'] = $oldRecord['etc];
}

Basically overwriting whatever was submitted by the user for those fields with whatever is already in the database.

Hope that helps!

Dave Edis - Senior Developer
interactivetools.com

By Djulia - November 29, 2013 - edited: November 29, 2013

Hi Rob,

>Is there an inbuilt function to set certain fields within a schema as read only?
I do not know if I understand your request correctly but, I use jQuery to make an fields read only (in field description or prefix).

$('input[name=myfield]').attr('readonly', 'readonly');

also .prop() function (jQuery 1.6+)

http://api.jquery.com/prop/

@Dave - I benefit from this occasion to ask you whether the version of jquery will be updated in a forthcoming version?

Thanks!

Djulia