How to fill in the default values in the xml subform field

270 views
Skip to first unread message

Александр Березуев

unread,
Aug 30, 2020, 6:03:18 AM8/30/20
to Joomla! General Development
Hi Guys,

In my module I have XML subform:
<field name="fieldname" type="subform"
    multiple="true"
    label="Subform Field" description="Subform Field Description"
    layout="joomla.form.field.subform.repeatable-table">
    <form>
          <field name="text_field1" type="text" label="Example Text1"/>
          <field name="text_field2" type="text" label="Example Text2/>
     </form>
</field>

It has a multiple feature so that many lines can be filled.

Question: how can I fill a string with standard values multiple times?

Roger Creagh

unread,
Aug 31, 2020, 4:33:58 AM8/31/20
to joomla-de...@googlegroups.com
Is there a reason for using a subform field type and not a simple list with the multiple option?

<field name="mylistvalue" type="list" default="" required="true" label="Select an option" description="" multiple="true" >
  <option value="">Please Select</option>
  <option value="0">Option 1</option>
  <option value="1">Option 2</option>
</field>

Or if you need to use a subform with fixed predefined values then instead of using text fields within the subform (which the user can enter arbitrary text in)  then use a list field type within the subform and set the option values as normal.

Or use separate checkboxes in the subform for each option. It depends what you are trying to achieve, but it sounds like you don't really need the complexity of a repeatable-table subform.


RogerCO

Александр Березуев

unread,
Aug 31, 2020, 4:46:26 AM8/31/20
to Joomla! General Development
My employer asks for a form to fill in demo data, so the select type is not suitable.

Demo data for example will be in my form 5 lines filled, but I can't.

понедельник, 31 августа 2020 г. в 11:33:58 UTC+3, roger...@googlemail.com:

Roger Creagh

unread,
Aug 31, 2020, 1:54:16 PM8/31/20
to joomla-de...@googlegroups.com
Sorry, I misunderstood.

What you have should provide the user with subform rows each containing two text fields. The user can add additional rows by using the + button.
I'm not sure that you need the layout="..." bit, I think it should work without specifying a layout unless you want to change the default
 By specifying that the subform has mulltiple="true" then it will render with the buttons for the user to add and delete rows, and reorder them. You can set a min and max number of rows, and also whether you want add, remove, move buttons for the rows using the field parameters.

I'm not sure quite what you are asking when you say "Question: how can I fill a string with standard values multiple times?". Which string, where? Are you wanting to pre-populate the text fields with default values?  In that case you might need to write a field definition in the models/fields folder and reference that in formsource="..." parameter for the subform.

If you want 5 lines showing to start with then set min="5" in the parameters, If you don't want the user to delete rows then set buttons="add,move" or whatever buttons you do want - buttons="" will remove the buttons.

Sorry not to be more helpful
RogerCO

Mathew Lenning

unread,
Sep 1, 2020, 7:15:16 PM9/1/20
to Joomla! General Development
Two ways to do this.

1. Build an associative array that has the same structure as your form

$data = array(
                 "fieldname" => array
                 (
                     "text_field1" => array(' standard values'),
                     "text_field2" =>  array(' standard values ' )
                 ));

$form->bind($data);

This will allow you to use dynamic  data 

2. use the default property in your xml definition

   <field name="text_field1" type="text" label="Example Text1" default="standard values "/>

hope this helps.
Reply all
Reply to author
Forward
0 new messages