Jump to content
Matze

password field always required?

Recommended Posts

Hey there,

is there a possibility to make a password field not required. Whatever i try (no check or check the required option in field definition) it is always set to "required" and gives an error () if i try to save or create a new page with this field in its template.

Required password was not specified, Missing required value

Is it possible? 

Thanks! 

Matze

 

Share this post


Link to post
Share on other sites

Well, thank you very much, but no, it’s a secondary password to set, for some reasons. But it's not set via Admin. But i need the field for the password. So the question is still: why is a password required if i uncheck "required" in the field definition?

Share this post


Link to post
Share on other sites
5 hours ago, Matze said:

Whatever i try (no check or check the required option in field definition) it is always set to "required"

Is your page unpublished? InputfieldPassword is set to required on unpublished pages regardless of what you might have chosen in the field settings - see here. Probably only @ryan could tell you why this is so.

You can work around the issue with a hook in /site/ready.php:

// You may need to modify "pass" to whatever your password field is named
$wire->addHookBefore('Field(name=pass)::getInputfield', function(HookEvent $event) {
    $page = $event->arguments(0);
    $field = $event->object;
    // Do some test on $page and/or $field to identify the cases where the password field should not be required
    // Then...
    $field->required = false;
});

 

  • Like 6

Share this post


Link to post
Share on other sites
On 2.4.2018 at 11:18 PM, Robin S said:

You can work around the issue with a hook in /site/ready.php:

The hook worked perfectly, thank you very much!

Now i just need to find out how to hide the password field in Admin, too. There is no "visibility" option for the password field? Any reason for this?

I tried to manage this over access control, but this was causing new problems. Unchecking the "view" checkbox for admin role ( and automatically guest, too) was disabling the possibility to check password in script via Password->matches().
 

Share this post


Link to post
Share on other sites
On 11/04/2018 at 7:17 PM, Matze said:

Unchecking the "view" checkbox for admin role ( and automatically guest, too) was disabling the possibility to check password in script via Password->matches().

There is an option in the field access tab "Make field value accessible from API even if not viewable" that would probably resolve that.

Alternatively you can prevent the field appearing in ProcessUser with this hook:

$wire->addHookAfter('ProcessPageEdit::buildFormContent', function(HookEvent $event) {
    if($this->process != 'ProcessUser') return;
    $form = $event->return;
    $pass = $form->getChildByName('pass'); // Assuming your password field is named "pass"
    if($pass) $form->remove($pass);
    $event->return = $form;
});

 

  • Like 1

Share this post


Link to post
Share on other sites
On 11.4.2018 at 10:25 AM, Robin S said:

There is an option in the field access tab "Make field value accessible from API even if not viewable" that would probably resolve that.

Thank you Robin, this worked very fine.

So I'm close: The password field isnt required anymore and it's hidden if the page is published.

Only if the page is unpublished it's still visible. Any reason for this? Or any idea how to hide completely, independent of published or not?
 

Thank you so much!
 

Share this post


Link to post
Share on other sites
8 hours ago, Matze said:

Only if the page is unpublished it's still visible. Any reason for this?

The reason in terms of the code is that a password inputfield is forced to display uncollapsed on unpublished pages because of this part of InputfieldPassword. There is no way to override this collapse status with a hook.

As for the reason "why?", I can only speculate that Ryan sees the password field as a special case that is unlike other fields, and does not expect it to be used apart from the single built-in usage in the user template.

8 hours ago, Matze said:

Or any idea how to hide completely, independent of published or not?

Did you try the hook I suggested in my previous post? I'm not clear on whether you are using the password field a second time in the user template or in some other template besides the user template. If it's the latter and you are not editing the page via ProcessUser (i.e. not under the Access > Users section of admin) then you would modify the early return test to check for template instead.

$wire->addHookAfter('ProcessPageEdit::buildFormContent', function(HookEvent $event) {
    $page = $this->process->getPage();
    if($page->template != 'your_template') return;
    $form = $event->return;
    $pass = $form->getChildByName('pass'); // Assuming your password field is named "pass"
    if($pass) $form->remove($pass);
    $event->return = $form;
});

 

  • Like 1

Share this post


Link to post
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

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...