Как использовать subform php joomla 3
Перейти к содержимому

Как использовать subform php joomla 3

  • автор:

Subform form field type

The subform form field type provides a method for using XML forms inside one another or reuse forms inside an existing form. If attribute multiple is set to true then the included form will be repeatable.

The Field has two «predefined» layouts for displaying the subform as either a table or as a div container, as well as support for custom layouts.

An example XML field definition for single mode:

An example XML field definition for multiple mode:

Example XML of exampleform.xml

An example XML of exampleform.xml with fieldsets

  

The subform XML may also be specified inline as an alternative to placing the subform XML in a separate file. The following example illustrates this:

  • type (mandatory) must be subform.
  • name (mandatory) is the unique name of the field.
  • label (mandatory) (translatable) is the descriptive title of the field.
  • description (optional) (translatable) is text that will be shown as a tooltip when the user moves the mouse over the drop-down box.
  • required (optional) The field must be filled before submitting the form.
  • message (optional) The error message that will be displayed instead of the default message.
  • default (optional) is the default value, JSON string.
  • formsource (mandatory) the form source to be included. A relative path to the xml file (relative to the root folder for the installed Joomla site) or a valid form name which can be found by JForm::getInstance().
  • multiple (optional) whether the subform fields are repeatable or not.
  • min (optional) count of minimum repeating in multiple mode. Default: 0.
  • max (optional) count of maximum repeating in multiple mode. Default: 1000.
  • groupByFieldset (optional) whether to group the subform fields by its fieldset (true or false). Default: false.
  • buttons (optional) which buttons to show in multiple mode. Default: add,remove,move.
  • layout (optional) the name of the layout to use when displaying subform fields.
  • validate (optional) should be set to Subform (note that this is case-sensitive!) to ensure that fields in the subform are individually validated. Default: Fields in the subform are not validated, even if validation rules are specified.
  • joomla.form.field.subform.default render the subform in a div container, without support of repeating. Default for single mode.
  • joomla.form.field.subform.repeatable render the subform in a div container, used for multiple mode. Support groupByFieldset.
  • joomla.form.field.subform.repeatable-table render the subform as a table, used for multiple mode. Supports groupByFieldset. By default each field is rendered as a table column, but if groupByFieldset=true then each fieldset is rendered as a table column.

If your field in the subform has additional JavaScript logic then it may not work in multiple mode, because do not see the fields which added by the subform field dynamically. If it happened then you need to adjust your field to support it. Next example may help:

jQuery(document).ready(function()< . here the code for setup your field as usual. jQuery(document).on('subform-row-add', function(event, row)< . here is the code to set up the fields in the new row . >) >);

Because of this some extra Joomla! fields may not work for now.

  • 1 Fields Validation and Filters
    • 1.1 Beware!

    Fields Validation and Filters [ править ]

    The subform form field does not provide the Validation and Filters for child fields.

    Addition: Since a security fix in Joomla 3.9.7 the filter=»example» attributes in subform child fields are supported and the fields will be validated; but NOT in custom form fields that extend the JFormFieldSubform class. You have to adapt such custom fields yourself!

    Beware! [ править ]

    All extensions that use subform fields MUST add an attribute filter to their subform child fields of type editor , textarea , text (maybe others, too) since Joomla 3.9.7 like it’s common for «normal» JForm fields, if you want to allow HTML input. Otherwise the validation falls back to STRING, which is the common behavior for «normal» JForm fields. Examples:

    filter="safehtml" filter="JComponentHelper::filterText" filter="raw" (bad decision in most cases)

    Example [ править ]

    After adding new rows selects are not «chosen».

    Here is an example how to reinit jQuery Chosen on newly added repeated rows:

    jQuery(document).ready(function()< jQuery(document).on('subform-row-add', function(event, row)< jQuery(row).find('select').chosen(); >) >);

    Or a PHP snippet to be used in e.g. your plugin in **onBeforeCompileHead** method or in your component view.

    $doc = JFactory::getDocument(); $js = ' jQuery(document).on(\'subform-row-add\', function(event, row)< jQuery(row).find(\'select\').chosen(); >) '; $doc->addScriptDeclaration($js);

    So newly added rows now are «chosen» now

    Subform data not getting stored to database on custom component.

    Add the following line to the beginning of your corresponding table class:

    protected $_jsonEncode = array('fieldnamehere');

    See also [ править ]

    Joomla Subform field

    We have inherited a Joomla project and need to implement a repeating field for product images. We’re having trouble understanding how to implement this in the database. Is there some naming convention to tell Joomla what table/foreign keys to use? We’ve got this in the xml file:

    Then we have the is pulled into the form edit.php file like this:

     
    form->getLabel('gallery_images'); ?>
    form->getInput('gallery_images'); ?>

    render Subform repeatable custom fields joomla4

    I have created one subform custom fields in my Joomla 4 article from backend and selected media filed at subform enter image description here enter image description here and use this code for load custom fields at joomla article YOUR_JOOMLA_WEBSITE_ROOT/templates/cassiopeia/html/com_content/article/default.php code :

     item; //use the field helper class to get the fields JLoader::register('FieldsHelper', JPATH_ADMINISTRATOR . '/components/com_fields/helpers/fields.php'); $fields = FieldsHelper::getFields($context, $article, true); // Added so as to access fields by their name // GET CUSTOM FIELDS foreach($fields as $field) < $fields[$field->name] = $field; > ?> 

    and use this code for fetch

     rawvalue; $class = $fields['gallery']->params->get('render_class'); $items = json_decode($programs, true);?> 
    ">

    now I want to render just subform custom fields value in joomla article

    YOUR_JOOMLA_WEBSITE_ROOT/templates/cassiopeia/html/com_content/article/default.php 

    but code above not work for load subform custom fields joomla4 but loaded repeatable custom fields joomla3 How to render subform custom fields at joomla4 article ?

    Saved searches

    Use saved searches to filter your results more quickly

    Cancel Create saved search

    You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.

    Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

    By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

    Already on GitHub? Sign in to your account

    Multi level subform #11551

    webchun opened this issue Aug 11, 2016 · 17 comments

    Multi level subform #11551

    webchun opened this issue Aug 11, 2016 · 17 comments

    Comments

    webchun commented Aug 11, 2016 •
    edited by joomla-cms-bot

    Steps to reproduce the issue
    • I’m using subform for my module parameters
    • I have this code on my xml :
    • This is the content of the item.xml

    and this is the content of subchild_items.xml

    Expected result

    The subform works properly

    Actual result

    It works partially. The subchild subform is displayed, but it’s breaking the next fieldset, and every time I added the new item, the subchild subform’s field is displayed twice

    System information (as much as possible)
    Additional comments

    The text was updated successfully, but these errors were encountered:

    webchun commented Aug 11, 2016
    Sieger66 mentioned this issue Aug 11, 2016
    gaelicwinter commented Aug 17, 2016

    @Fedik, any idea when the multilevel subform code might be available? I’m stuck with the need, and while I probably don’t have as much experience with jquery as you, I am happy to help in any way I can. It will probably take me 2-3 weeks to come up with my own solution to use in my own joomla site, and I’d rather devote that to the core project if possible. I’m good with joomla, php, css, etc, and ok with js and such.

    Happy to contribute if I can.

    Fedik commented Aug 17, 2016

    Some months ago I tried to fix it for my own project, but did not got any success with multilevel subform.
    There need some more coding and changes in the script and in the layout.
    I am not sure that it can be fixed soon.

    olejenya commented Aug 26, 2016

    showon = «test: 1» This is just the minimum that can be used in multiple = «true», that everything was beautiful.

    It would be nice to make this type of field that would work all. The modules have become much brighter and more convenient to the end user ispolbzovanii Joomla!

    showon=»test:1″ Это как раз тот минимум , который можно было использовать в multiple=»true» , что бы все было красиво.
    Было бы неплохо сделать этот тип поля , что бы все работало. Модули стали бы намного ярче и удобней в исполбзовании для конечного пользователя джумлы

Добавить комментарий

Ваш адрес email не будет опубликован. Обязательные поля помечены *