Jump to content

Recommended Posts

Posted

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

Posted

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.

Posted

It's not attributes for fields, but more html attributes on the inputfield render output. As you say correctly it's not something saved with the inputfield.

  • Like 1
Posted

WillyC,

This value is something that will get set when the user is logged in via a 3rd party authentication provider.

I need superusers and admins to see the checkbox, but not be able to change it.

Posted

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
Posted

Hi Ryan,

I hadn't ever really looked at the field visibility options, didn't realize there was "not shown in editor".

Showing a message is a great idea — Thanks!

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
  • Recently Browsing   0 members

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