pollen8
non lue,22 juil. 2011, 11:18:5522/07/2011Connectez-vous pour répondre à l'auteur
Connectez-vous pour transférer le message
Vous n'êtes pas autorisé à supprimer des messages dans ce groupe
Connectez-vous pour signaler le message
Afficher le message d'origine
Soit les adresses e-mail sont anonymes pour ce groupe, soit vous devez disposer de l'autorisation "Afficher les adresses e-mail des membres" pour afficher le message d'origine.
à 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