JFormField & sub forms: question regarding the xpath statment JForm uses

541 vues
Accéder directement au premier message non lu

pollen8

non lue,
22 juil. 2011, 11:18:5522/07/2011
à joomla-de...@googlegroups.com
I'm trying to write a new JFormField type, which is a button which will load up a modal form with a set of fields you can add/remove from, (think adding dropdown value/label options):

[value] : [label] [add/remove]

what I thought would be neat would be to create those repeatable elements via xml just as you would using the usual JForm xml, below is an example.

<?xml version="1.0" encoding="UTF-8"?>
<form>
    <fields name="params">
        <fieldset name="plg-list-filter_view">
            <field name="dropdown-options"
                type="modaljson"
                label="click to add dropdown options">
               
                <fields name="params">
                    <fieldset name="filter_view_modal" repeat="1">
                        <field name="value"
                            type="text"
                            label="value"/>
                       
                        <field name="label"
                            type="text"
                            label="label" />
                           
                        </fieldset>
                </fields>            
            </field>
        </fieldset>
    </fields>
</form>



here's the start of my JFormField class:

class JFormFieldModaljson extends JFormField
{
    /**
     * The form field type.
     *
     * @var        string
     * @since    1.6
     */
    protected $type = 'Modaljson';

    /**
     * Method to get the field input markup.
     *
     * @return    string    The field input markup.
     * @since    1.6
     */
    protected function getInput()
    {
       $subForm = new JForm($this->name, array('control'=>'jform'));
        $xml = $this->element->children()->asFormattedXML();
        $subForm->load($xml);
        $subForm->setFields($this->element->children());
        $str = array();
        $str[] = '<ul>';
         foreach ($subForm->getFieldset($this->element->getAttribute('name').'_modal') as $field) {
                    $str[] = '<li>
                        '.$field->getLabel($field->name). $field->getInput().'
                    </li>';
            };
        $str[] = '</ul>';
        return implode("\n", $str);
    }
}


which works great, except...... that JForm will get all fields that are descendants of a requested fieldset :

JForm::findFieldsByFieldset() has this code:
$fields = $this->xml->xpath('//fieldset[@name="'.$name.'"]//field | //field[@fieldset="'.$name.'"]');

So my main JForm renders the two sub form elements, and then the sub form re-renders them

if I tweak that xpath to

$fields = $this->xml->xpath('//fieldset[@name="'.$name.'"]/field | //field[@fieldset="'.$name.'"]');

then I don't get the sub form fields written out in the main form, which is what I'm after.

For the time being I'm overriding JForm in my component so its not a big issue, but I was wondering if there was a reason why the xpath statement was like that or is it just that no-one was twisted enough to think of making <fields> descendants of other fields?
However, I think this mehtod of using sub forms could be beneficial to a lot of 3rd party components and or Joomla itself, so I was hoping that I could write a patch against the core, but I need advice on if the origianl xpath statment is there for a reason before continuing along that route

-Rob




G. D. Speer

non lue,
22 juil. 2011, 15:04:5122/07/2011
à joomla-de...@googlegroups.com
Rob,
Great idea/solution - I suggest you post this to Joomla-dev-cms to get attention from the core crowd.
 
 
--
You received this message because you are subscribed to the Google Groups "Joomla! General Development" group.
To view this discussion on the web, visit https://groups.google.com/d/msg/joomla-dev-general/-/I2h3EgB5HoEJ.
To post to this group, send an email to joomla-de...@googlegroups.com.
To unsubscribe from this group, send email to joomla-dev-gene...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/joomla-dev-general?hl=en-GB.

Mark Dexter

non lue,
22 juil. 2011, 18:11:0022/07/2011
à joomla-de...@googlegroups.com
Rob, could you propose a patch to the platform with this feature? Thanks. Mark

pollen8

non lue,
24 juil. 2011, 05:07:5224/07/2011
à joomla-de...@googlegroups.com
hi Mark

Yes, I'll propose it with the new form field type (I'm calling it modalrepeat) as without that there isn't much point to it.
Should I put that in the tracker or in my fork of the 1.7 platform on github?

-Rob

pollen8

non lue,
25 juil. 2011, 04:11:2725/07/2011
à joomla-de...@googlegroups.com

JSamir

non lue,
23 févr. 2012, 06:01:1323/02/2012
à joomla-de...@googlegroups.com
What happened to this proposal? In 2.5 the findFieldsByFieldset() method is the same without the additons you asked for. Your formfield is not there too, which i find is pretty nice to have in the core to show the power of JForm, to be an inspiration (just as this topic was for me).
Répondre à tous
Répondre à l'auteur
Transférer
0 nouveau message