? Success

User tests: Successful: Unsuccessful:

avatar okonomiyaki3000
okonomiyaki3000
18 Oct 2016

Pull Request for Issue # .

Summary of Changes

When getting the default value for a form element, first check if the <field> node has a child <default>. Use the value of the <default> node if it exists, otherwise use the the default attribute.

The main value of this will be in conjunction with field types such as subform which take their default values as json. Writing correct json into an xml attribute kind of sucks as you must use a lot of &quot; and the whole thing gets very long and illegible. By using a dedicated node, you can simply wrap the json inside of <![CDATA[]]> and write it normally. So, instead of:

<field type="subform" name="myfield" default="{&quot;myfield0&quot;:{&quot;key1&quot;:&quot;value1",&quot;key2&quot;:&quot;value2&quot;},&quot;myfield1&quot;:{&quot;key1&quot;:&quot;value3",&quot;key2&quot;:&quot;value4&quot;},&quot;myfield2&quot;:{&quot;key1&quot;:&quot;value5",&quot;key2&quot;:&quot;value6&quot;}}" /> 

You could have:

<field type="subform" name="myfield">
    <default><![CDATA[
    {
        "myfield0": {"key1": "value1", "key2": value2},
        "myfield1": {"key1": "value3", "key2": value4},
        "myfield2": {"key1": "value5", "key2": value6}
    }
    ]]></default>
</field>

Testing Instructions

Create a field and give it a <default> element as a child. Load the form and notice that the value of the <default> node is used for your field.

Documentation Changes Required

Probably.

avatar okonomiyaki3000 okonomiyaki3000 - open - 18 Oct 2016
avatar okonomiyaki3000 okonomiyaki3000 - change - 18 Oct 2016
Status New Pending
avatar joomla-cms-bot joomla-cms-bot - change - 18 Oct 2016
Labels Added: ?
avatar joomla-cms-bot joomla-cms-bot - change - 18 Oct 2016
Category Libraries
avatar Fedik
Fedik - comment - 20 Nov 2016

I have tested this item successfully on 08fa825


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/12451.

avatar Fedik Fedik - test_item - 20 Nov 2016 - Tested successfully
avatar Fedik
Fedik - comment - 20 Nov 2016

cool idea, also it allow to add huge text as default value for textarea, editor, more easy

avatar Fedik
Fedik - comment - 20 Nov 2016

test example for textarea:

<field type="textarea" name="myfield1" class="input-xxlarge" rows="6">
  <default><![CDATA[
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Cras risus velit, malesuada ut feugiat semper, blandit sit amet velit.
Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus.
  ]]></default>
</field>

for editor:

<field type="editor" name="myfield2" >
  <default><![CDATA[
<h3>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</h3>
<p>Cras risus velit, malesuada <strong>ut feugiat semper</strong>, blandit sit amet velit.<br />
Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus.</p>
  ]]></default>
</field>
avatar laoneo
laoneo - comment - 26 Nov 2016

I like this but I think the check should be flipped, first check if there is a default attribute and then check for a default node. Just to be 100% BC safe 😧

avatar laoneo
laoneo - comment - 26 Nov 2016

Just asked myself, do we even need a <default> tag? Would that not also also work:

<field type="textarea" name="myfield1" class="input-xxlarge" rows="6">
  <![CDATA[
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Cras risus velit, malesuada ut feugiat semper, blandit sit amet velit.
Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus.
  ]]>
</field>
avatar Fedik
Fedik - comment - 26 Nov 2016

@laoneo and how about subform then, with changes from another pull #12813 ?

<field type="subform" name="myfield" multiple="true">
    <![CDATA[
    [
       {"key1": "value1", "key2": value2},
       {"key1": "value3", "key2": value4},
       {"key1": "value5", "key2": value6}
    ]
    ]]>
   <form>
            <field name="key1"  label="key1"  type="text" />
            <field name="key2"  label="key2"  type="text" />
    </form>
</field>

looks not very good without <default>,
I think use <default> tag is a good idea.

avatar laoneo
laoneo - comment - 26 Nov 2016

True...

On Nov 26, 2016 3:43 PM, "Fedir Zinchuk" notifications@github.com wrote:

@laoneo https://github.com/laoneo and how about subform then, with
changes from another pull?

looks not very good without ,
I think use tag is a good idea.


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
#12451 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAPUwCPW2zhv6o3B2Hp9FYcZy33DvAWHks5rCEWhgaJpZM4KZYfR
.

avatar okonomiyaki3000
okonomiyaki3000 - comment - 28 Nov 2016

@laoneo You might be right about precedence. It's not likely to make any difference but it could, in theory.

Anyone else agree it should be flipped or see a reason why it shouldn't?

avatar Fedik
Fedik - comment - 28 Nov 2016

I think flipping will be more safe, in case if some extension already use <default> tag in own needs

avatar okonomiyaki3000
okonomiyaki3000 - comment - 29 May 2017

Finally I got around to changing the precedence.

avatar Fedik
Fedik - comment - 29 May 2017

@okonomiyaki3000 it is works, if formsource is external file,
but broken when the form source is "children":

<field type="subform" name="myfield" multiple="true">
  <default><![CDATA[
[
        {"key1": "value1", "key2": "value2"},
        {"key1": "value3", "key2": "value4"},
        {"key1": "value5", "key2": "value6"}
]
]]></default>
	<form>
	  <field name="key1"  label="key1"  type="text" />
	  <field name="key2"  label="key2"  type="text" />
	</form>
</field>

@laoneo maybe you have an idea?

avatar okonomiyaki3000
okonomiyaki3000 - comment - 31 May 2017

@Fedik The problem here is in JFormFieldSubform::setup()

if (!$this->formsource)
{
	// Set the formsource parameter from the content of the node
	$this->formsource = $element->children()->saveXML();
}

This is too flexible. A proper implementation would be like this:

if (!$this->formsource && $element->form)
{
	// Set the formsource parameter from the content of the node
	$this->formsource = $element->form->saveXML();
}

Changing it now may break BC. I will check a little. However, your example can work if the <default> and <form> elements are swapped. As long as <form> is first, it will be fine.

avatar okonomiyaki3000
okonomiyaki3000 - comment - 31 May 2017

Maybe it does not need to be seen as a break since, even now, only a <form> element will actually work there.

avatar okonomiyaki3000
okonomiyaki3000 - comment - 31 May 2017

OK, so here's the fix. Technically, it's a change to current behavior.

Before
A subform with no formsource will get its formsource from its children.
The first child must be a <form> element or the field will be broken in some way.
Any subsequent children (<form> or otherwise) will have no effect on the field.

After
A subform with no formsource will get its formsource from its first <form> child.
Any child node other than the first <form> will just be ignored.

Essentially, any subform definition that currently works will continue to work just the same. Some definitions which are currently broken (should such things exist at all), may be fixed.

avatar Fedik
Fedik - comment - 31 May 2017

I have tested this item successfully on 078a86c


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/12451.

avatar Fedik Fedik - test_item - 31 May 2017 - Tested successfully
avatar franz-wohlkoenig
franz-wohlkoenig - comment - 13 Jun 2017

@Fedik can you please test again?

avatar laoneo
laoneo - comment - 13 Jun 2017

I have tested this item successfully on 529f83f

Tested it with custom fields with #16659. If this one gets in, #16659 will be ready to be tested.


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/12451.

avatar laoneo laoneo - test_item - 13 Jun 2017 - Tested successfully
avatar Fedik
Fedik - comment - 13 Jun 2017

I have tested this item successfully on 529f83f


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/12451.

avatar Fedik Fedik - test_item - 13 Jun 2017 - Tested successfully
avatar franz-wohlkoenig franz-wohlkoenig - change - 13 Jun 2017
The description was changed
Status Pending Ready to Commit
avatar joomla-cms-bot joomla-cms-bot - edited - 13 Jun 2017
avatar franz-wohlkoenig
franz-wohlkoenig - comment - 13 Jun 2017

RTC after two successful tests.

avatar rdeutz rdeutz - change - 15 Jun 2017
Status Ready to Commit Fixed in Code Base
Closed_Date 0000-00-00 00:00:00 2017-06-15 06:52:44
Closed_By rdeutz
Labels Added: ?
avatar rdeutz rdeutz - close - 15 Jun 2017
avatar rdeutz rdeutz - merge - 15 Jun 2017
avatar laoneo
laoneo - comment - 15 Jun 2017

As this one get in now, can you guys please test #16659. Would be nice to support that feature in custom fields, would make the default value attribute much more stable.

Add a Comment

Login with GitHub to post a comment