Jump to content

Recommended Posts

Posted

Is there a way to prefill a field with a default value.

I have a simple text field that 99% of the time will contain the same text but for the other 1% it needs to be editable so rather than paste in the same text for nearly every page I'm trying to find away to prefill the value of the input.

Posted

The field has an option for a default value though it will only apply to newly created pages (in case you have previously created some of them).

My bad, this does not exist haha, I think only integer has this. But you could certainly do this with an "after hook" on ProcessPageEdit::buildForm and edit the value of the field in question. I dont have an immediate example but there is probably some around the forum

Posted

You could edit the output in the template file and use the new $page->if() method.

https://processwire.com/api/ref/page/if/

So there might be no real need in setting a real value. Add a note or description to tell and explain editors the field behaviour.

You could define that default value somewhere in your config.php or even in a dedicated settings page to keep it editable - at least for superusers.

 

  • Like 2
Posted
22 hours ago, wbmnfktr said:

You could edit the output in the template file and use the new $page->if() method.

https://processwire.com/api/ref/page/if/

So there might be no real need in setting a real value. Add a note or description to tell and explain editors the field behaviour.

You could define that default value somewhere in your config.php or even in a dedicated settings page to keep it editable - at least for superusers.

 

Thanks, that's one way if i can't hook something. It'd be nice to have a default field though.

  • Like 2

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...