Jump to content

Default value for radio button (page field)


lenoir
 Share

Recommended Posts

Hey there,

I have a page field in the form of radio buttons, where the user can select the importance of the article: Very important, important, normal. 

I would like to make the default value "normal", but can't think of any way of doing it.

Any help?

Thanks

Link to comment
Share on other sites

Hi Lenoir, I think this has come up a few times and I don't think there is a way of setting a default in the admin side.

What you can do however is use if/else statements in the template:

if ($page->field == "very_important") {
  // do something
} elseif ($page->field == "important") {
 // do something different
} else {
 // user has either selected normal or left it blank so use normal
}
 
  • Like 1
Link to comment
Share on other sites

It's not always good practice to have default value set for various reasons and there's some discussion about it in the forums.

You have "normal" .. is it really needed to have that as a selectable state? All default entries are "normal" and should be handled in template code.

Just create option with dropdown (as radios have no blank) and have "important" and "very important" as states.

  • Like 2
Link to comment
Share on other sites

Soma: that's an interesting thought.

I don't know what the discussions are in the forum, but i can only see one small issue with this solution: it can be confusing to select a blank item of a dropdown if the user wants to go back to the "normal" state.

Still I'll give it a go, since it'd be a better solution than a radio without default value.

Thanks.

Link to comment
Share on other sites

Hey, is this new?
Cool: mods.pw/3y

All modules now have their own short URL off mods.pw. The letter combo used is the base 62 value of the module's ProcessWire page ID minus 1000. For example "3y" translates to 1246. Just a way to keep them as short as possible. 

  • 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

×
×
  • Create New...