Jump to content

Set field attributes via API


renobird
 Share

Recommended Posts

I'm trying to set an checkbox in the user template to disabled via the API.

Tried this:

$user->of(false);
$user->checkbox_name->attr("disabled","disabled");
$user->save();

Results in:

Fatal error: Call to a member function attr() on a non-object

Link to comment
Share on other sites

I think you have to apply the disabled attribute just prior to rendering in the GUI, so a module doing this in its init()...

$this->addHookBefore('Inputfield::render', $this, 'myHook' );

And then having this...

protected function myHook(HookEvent $event)
{
if( 'FieldNameYouWantDisabled'' === $event->object->name )
 $event->object->attr( 'disabled', 'disabled' );
}

...should be enough.

Link to comment
Share on other sites

I would probably set the visibility of that field to "not shown in editor". Rather than have your hook try to adjust attributes of a field, just have it display a message:

if($page->your_checkbox) $this->message("User is logged in"); 
  else $this->message("User is NOT logged in."); 
  • Like 2
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...