renobird Posted September 13, 2012 Share Posted September 13, 2012 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 More sharing options...
netcarver Posted September 13, 2012 Share Posted September 13, 2012 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 More sharing options...
renobird Posted September 13, 2012 Author Share Posted September 13, 2012 That makes sense, the attributes for fields aren't stored in the DB, so you have to modify them before render. Link to comment Share on other sites More sharing options...
Soma Posted September 13, 2012 Share Posted September 13, 2012 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. 1 Link to comment Share on other sites More sharing options...
WillyC Posted September 13, 2012 Share Posted September 13, 2012 why.disablas checkbaxen user tamplate ? go.admin>modules>process>profile en.removar checkbaxen btw $user->checkbax_name es integar no.object Link to comment Share on other sites More sharing options...
renobird Posted September 14, 2012 Author Share Posted September 14, 2012 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. Link to comment Share on other sites More sharing options...
ryan Posted September 14, 2012 Share Posted September 14, 2012 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."); 2 Link to comment Share on other sites More sharing options...
renobird Posted September 14, 2012 Author Share Posted September 14, 2012 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! Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now