4

I want to add following form field in module settings like -

<field name="fb_posttype" type="checkboxes" label="Post types">         
    <option value="status" >Statuses</option>
    <option value="link">Links</option>
    <option value="photo">Photos</option>
    <option value="video">Videos</option>
    <option value="event">Events</option>
</field>

but most of them will be checked by default when user views module settings not after they check and click save at first.I saw there is a 'default' parameter but don't know how do i apply it for this field.

So how do i keep some checkboxes checked by default in the above fb_posttype field in module settings.FYI joomla version 2.5.11

2

if you want that the values link and video be checked by default, so you do something like this:

<field name="fb_posttype" type="checkboxes" checked="link,video" label="Post types">         
    <option value="status" >Statuses</option>
    <option value="link">Links</option>
    <option value="photo">Photos</option>
    <option value="video">Videos</option>
    <option value="event">Events</option>
</field>

you can do something like this too:

<field name="fb_posttype" type="checkboxes" label="Post types">         
    <option value="status">Statuses</option>
    <option value="link" checked="true">Links</option>
    <option value="photo">Photos</option>
    <option value="video" checked="true">Videos</option>
    <option value="event">Events</option>
</field>
  • Joomla rocks this site was needed for faster joomla answers.but csbenjamin your solution not working, i pasted in my module's xml file and loaded module from module manager from admin side and seeing all checkboxes unchecked! – dev-m Apr 24 '14 at 15:33
  • @professional I just tested it here and it works. What joomla version are you using? I pasted this code in administrator/components/com_content/models/forms/article.xml file and write <?php echo $this->form->getInput('fb_posttype'); ?> in administrator/components/com_content/views/article/tmpl/edit.php file and when I try to edit some article, the checkbox is showed with the default values checked. If you have anything in the fb_posttype property coming from your model, it is not going to use the default values – csbenjamin Apr 24 '14 at 15:55
  • Past your module code here, it will help to find the problem. – csbenjamin Apr 24 '14 at 16:03
  • joomla version 2.5.11 and exactly same code as yours.but i pasted this code in module's xml file, not the way you tested providing the links.So why not you open a joomla module's xml file and paste as a field for the module settings. – dev-m Apr 24 '14 at 16:06
  • I saw the problem. This joomla version doesn't support default value in xml, in case of this field type. You need check in your module code if is the first time, if so, set the fb_posttype property as a array with the default values. – csbenjamin Apr 24 '14 at 16:10
0

I imagine you could so something like:

<field name="fb_posttype" type="checkboxes" label="Post types" checked="status">         
    <option value="status" >Statuses</option>
    <option value="link">Links</option>
    <option value="photo">Photos</option>
    <option value="video">Videos</option>
    <option value="event">Events</option>
</field>

Or whatever you wish for the default to be.

  • 1
    The JFormFieldCheckboxes class don't use the default attribute. Instead, it uses the checked attribute. See my answer – csbenjamin Apr 24 '14 at 15:23
  • Alright, maybe I misinterpreted the docs(api.joomla.org/cms-3/classes/JFormFieldCheckboxes.html). – Milton Bryant Apr 24 '14 at 15:29
  • yeah, the default property belongs to the parent class and the JFormFieldCheckboxes class doesn't use that. – csbenjamin Apr 24 '14 at 15:46
0

I, in-case if you want your default value to be status then you just add an attribute default in the field and set the value, but here you can set only one default value in the field. Rest of values should be done only in the option here you have to add an attribute checked="true"

This works fine. Hope it may helps you

<field name="fb_posttype" type="checkboxes" default="status"  label="Post types">         
  <option value="status" >Statuses</option>
  <option value="link" checked="true" >Links</option>
  <option value="photo" checked="true">Photos</option>
  <option value="video">Videos</option>
  <option value="event">Events</option>
</field>
  • The checked=true doesn't work in joomla 2.5. And the default value works only to one value as you said. – csbenjamin Apr 25 '14 at 11:15
  • @priya this way not working as csbenjamin said, wish all those fields worked as developers might need those fields in module settings very much indeed. – dev-m Apr 25 '14 at 13:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.