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

  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Similar Content

    • By Robin S
      Page Reference Default Value
      Most ProcessWire core inputfield types that can be used with a Page Reference field support a "Default value" setting. This module extends support for default values to the following core inputfield types:
      Page List Select Page List Select Multiple Page Autocomplete (single and multiple) Seeing as these inputfield types only support the selection of pages a Page List Select / Page List Select Multiple is used for defining the default value instead of the Text / Textarea field used by the core for other inputfield types. This makes defining a default value a bit more user-friendly.
      Note that as per the core "Default value" setting, the Page Reference field must be set to "required" in order for the default value to be used.
      Screenshot

       
      https://github.com/Toutouwai/PageReferenceDefaultValue
      https://modules.processwire.com/modules/page-reference-default-value/
    • By Guy Verville
      I am trying to implement a Repeater Matrix which contains a Page field (there are four fields, an image field, one text field and two page fields). The example given in the readme.txt is self-explanatory. However, this seems not to work with a page field. Say my page field is called "attached_ceramic_skus":
      <?php foreach($page->test_matrix as $item) { echo " <h3>$item->headline</h3> <=works <img... $item->image->url </> <= works foreach ($item->attached_ceramic_skus as $skus)... <= throws an error "; } } } When I debug this line, I see my image and text fields in the $item array, but not the page fields. But these fields are there and working when I enter data. I have understood how they are kept in the database. What is the method/hook to read this type of field?
    • By mikeuk
      (apologies if this looks too similar to previous topic I created, seems more logical as a new topic)
      I'm curious if anyone here is implementing something along the lines of Drupal's block / Joomla's custom (editable) module functionality?
      In other words, areas that are editable in the backend, that can be placed on multiple pages without needing to re-enter the content on each page it is used.
      I tried to do this using a page as a block, and then field type Page (to get a page within a page), but this led to issues with rendering, and more important this creates an object $page->fieldtypePage which is exceptionally large, so I would prefer to avoid that route.
      My guess is those that do it, do it outside of PW with PHP. But the 'blocks' being editable and creatable by a site editor is important so I need to explore this or find a different solution (or tell the client no-can-do).
    • By Matt
      Hello everyone! I recently downloaded ProcessWire and after playing around with it I've found its flexibility and ease of use to be really promising.
      I'm working on a site to publicize upcoming live music events and archive past events at our venue. Each event has the usual start time/end time/price/etc fields and can be associated with any number of bands (usually just one or two). Each band has name/website/description (short bio)/image fields. At the moment I have a page field on my event template allowing each event to be tagged with the required bands, either by choosing existing band pages (for bands which have played at our venue before) or by creating a new band page. I can then reference each band's name/website/description/image in the event template php.
      There are two key ways users will discover events on the public-facing site:
      1) Through the events index page, listing events which can be filtered using dates and keywords
      2) Through the band index page, listing bands whose pages will list past/upcoming events where they have performed.
      However, since:
      a) many bands have gone through minor lineup changes since they started playing at our venue,
      b) many bands have released (and want to promote) new material since they started playing at our venue,
      each band's description and image fields might (but not always) need to vary between events. I would like past event pages to show the band's description/image that was relevant when the event occurred, not the most recent revision. On adding band pages to new events pages, I would like the default description/image to be the most recent version for the band, with the option to replace this with a new description/image if required. It would be unnecessary to provide a new description/image for each band at each event if there were no lineup changes or releases of new material since they last performed.
      My first thought was to have a repeater field for description/image/start time/end time on the band template, where the start and end times help my php template decide which description and image to pair with a particular event. However, the band page field on the events template will not allow me to edit the referenced band page's attributes; it only lets me select band pages and reorder them. If I wanted to update the band description (while preserving the history of previous revisions) I would therefore have to find that band's page elsewhere in the admin then add a repeater row and enter the new description there, keeping the image field blank for that row if the image doesn't need updating. This would require the start time (of the new row) and end time (of the previous row) to be input manually... I'm convinced there must be a simpler way to maintain the links between events and band info.
      My current structure is:
      Home
      -- Events Index
      ---- Event 1
      ---- Event 2
      ---- Event 3
      -- Bands Index
      ---- Band 1
      ---- Band 2
      ---- Band 3
      Apologies if I've misused any terminology  Could anyone advise on sensible strategies for achieving this using Core ProcessWire or modules? Thanks!
    • By abdus
      Hey,
      I'm building a website with following page hierarchy
      home/     /blog (template: listing)         /tags (template: tags)             tag1 (template: tag)             tag2             tag3         post1 (template: post)         post2         post3     /development (template: listing)         /tags (template: tags)             tag1 (template: tag)             tag2         post1 (template: post)         post2
      Ok, so I created a Page field to reference tag pages for categorization of posts in different listings. I set up the field to use InputfieldPageAutocomplete module for quickly referencing and creating any number of tags within a post. However, during the setup, Processwire allows me to pick only one parent. I want to change this behaviour such that when searching for a tag, it should only search under its own listing. Specifically, posts under /development should only be able to reference tags under /development/tags and those under /blog should reference tags under /blog/tags etc. Also, when I create a new tag, it should create under its own tags page.
      I don't want to use a tags page under the homepage, because I want the URL structure to be /blog/tags/journal or /dev/tags/processwire etc, not /tags/processwire. I know I can use input()->urlSegments to achieve the url structure I want, and I did it like that in the past, but it felt too hacky to change the paths for pages from their own path in page tree. I tried hooking into InputfieldPage:processInputAddPages method to make the field accept the correct tags page, but I couldnt make it work.
      How can I achieve this?
×
×
  • Create New...