2

I have the basic xml file where in I call subforms into two tabs. Called Tab 1 and Tab 2. The content of this file is below.

mod_something.xml

<fieldset  name="tab1">
    <field name="storymaker" type="subform"
           formsource="/modules/mod_something/models/forms/storymaker.xml"
           min="1"
           max="9999999999"
           multiple="true"
           layout="joomla.form.field.subform.repeatable-table"
           groupByFieldset="false"
           buttons=""
           label="MOD_SOMETHING_-STORYMAKER-_LABEL"
           description="MOD_SOMETHING_-STORYMAKER-_DESC" />
        </fieldset>

        <fieldset  name="tab2">
    <field name="characters" type="subform"
           formsource="/modules/mod_something/models/forms/characters.xml"
           min="1"
           max="9999999999"
           multiple="true"
           layout="joomla.form.field.subform.repeatable-table"
           groupByFieldset="false"
           buttons=""
           label="MOD_SOMETHING_-CHARACTERS-_LABEL"
           description="MOD_SOMETHING_-CHARACTERS-_DESC" />
        </fieldset>

Now in the form that is loaded into tab1 I have this content.

storymaker.xml

<?xml version="1.0" encoding="UTF-8"?>
<form>
  <field name="characterselection" label="" type="characterselection"/>
</form>

the form in tab 2 consists out of this:

characters.xml

<?xml version="1.0" encoding="UTF-8"?>
<form>
  <field
    name="character_name"
    type="text"
    default=""
    label="MOD_SOMETHING_-CHARACTERNAME-_LABEL"
    description="MOD_SOMETHING_-CHARACTERNAME-_DESC"
    size="10"
  />
</form>

In tab 1 I use a custom field this custom field is build up like this:

<?php

// Check to ensure this file is included in Joomla!
defined('_JEXEC') or die('Restricted access');

jimport('joomla.form.formfield');
$document = JFactory::getDocument();
$jinput = JFactory::getApplication()->input;
$characters = $params->get('characters');
//$characters1 = $jinput->json->get('characters');
//$characters2 = $jinput->get('characters', null, null);
//$characters3 = $jinput->get->get('characters', NULL, NULL);
//$characters4 = $jinput->post->get('characters', NULL, NULL);
//$characters5 = $jinput->server->get('characters', NULL, NULL);
class JFormFieldCharacterSelection extends JFormField {

protected $type = 'characterselection';

public function getInput() {

  foreach ($characters as $character) {
    $character[] = $row->character_name;
  }
  // Merge any additional options in the XML definition.
  $options = array_merge(parent::getInput(), $character);
  return $options;
}
}

I have already tried everything I could think off but to no good. So here I am asking for your help.

what do I want to achieve

A) In tab2 I have a list of names created via a repeatable subform so that it can be 10 names or a 1000.

B) In tab1 I have another repeatable subform wherein I want to display a dropdown generated from the names given in tab2.

C) Then I want to show these names on the frontend via the normal foreach used for the subforms.

$storymaker = $params->get('storymaker');
foreach ($storymaker as $sm) :
  echo $sm->characterselection . ' ';
  echo '<br><br>';
endforeach;

what have I achieved so far

Sadly I only have achieved A. So I need help with B and I think that if that works C goes automatically alright but if not I might need help with that as well.

what have I tried so far

I tried every single thing I could find on the internet about subforms and using parameters from a module inside a module. You can see parts of this left in the above code (commented).

sorry for not being able to give short pinpointed code.

I had to put up all the files that are related to my problem otherwise I think no one would be able to understand what I am talking about. But sorry for the long text and code pieces.

thanks everyone for helping.

1

I solved this doing it a bit different.

B is done via this code which grabs all the inputs and converts them to a select box. Then when the user makes a selection it copies that selection to a normal text form field. This is the field that you load to get the results for C. When the user hasn't selected anything it shows the word character in the select box.

        (function ($) {
          $(document).ready(function() {
            $(".selectArea").each(function(i) {
              $(this).addClass("selectBox" + (i+1));
            });
            var values = $("input[id^='jform_params__characters__characters'][id$='__character_name']").map( function(){return $(this).val(); }).get();
            var optionsPlaceholder = '###OPTIONS###';
            var optionPlaceholder = '###OPTION###';
            var select = '<select class="selectInput">' + optionsPlaceholder + '</select>';
            var option = '<option>' + optionPlaceholder + '</option>';
            var options = '';
            for (var i = 0; i < values.length; i++) {
                var currentOption = option.replace(optionPlaceholder, values[i]);
                options += currentOption;
            }
            var selectBox = select.replace(optionsPlaceholder, options);
            var $select = $(selectBox);
            $(".selectBox").html($select);
            $(".selectInput").each(function(i) {
              $(this).addClass("selectInput" + (i+1));
            });
            $("input[id^='jform_params__storymaker__storymaker'][id$='__characterselection_save']").each(function(i) {
              $(this).addClass("selectInputSave selectInputSave" + (i+1));
            });
          });

          $(document).on('change', '.selectInput', function() {
            var savevalue = (this.value);
            var selectClassRaw = $(this).attr("class").replace('selectInput selectInput', '');
            $('.selectInputSave' + selectClassRaw).val(savevalue);
          });

          $(document).ready(function() {
            $(".selectInputSave").each(function() {
              var storedValue = (this.value);
              var storedClassRaw = $(this).attr("class").replace('selectInputSave selectInputSave', '');
              if ((this.value).length > 0) {
                $('.selectInput' + storedClassRaw).val(storedValue);
              } else {
                $('.selectInput' + storedClassRaw).prepend('<option>Character</option>').val('Character');
              }
            });
            $('.selectInputSave').parents('.control-group').addClass('hiddenSaveInput');
          });
        })(jQuery);

Keep in mind that the above code does not exactly work together with the previous codes as storymaker.xml is completely different

  <?xml version="1.0" encoding="UTF-8"?>
  <form>
    <field name="mode"
      type="radio"
      default="story"
      label="MOD_SOMETHING_-MODE-_LABEL"
      description="MOD_SOMETHING_-MODE-_DESC"
      class="btn-group btn-group-yesno"
      >
      <option value="story">MOD_SOMETHING_-STORY-_OPTION</option>
      <option value="speech">MOD_SOMETHING_-SPEECH-_OPTION</option>
    </field>
    <field name="characterselectiongenerate" showon="mode:speech" label="MOD_SOMETHING_-CHARACTERSELECTION-_LABEL" description="MOD_SOMETHING_-CHARACTERSELECTION-_DESC" type="characterselectiongenerate"/>
    <field name="characterselection_save" type="text" default="" label="MOD_SOMETHING_-CHARACTERNAME-_LABEL" description="MOD_SOMETHING_-CHARACTERNAME-_DESC" size="10" />
  </form>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.