Skip to content
New issue

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

Use of 'source=""' for select in 'multiple' doesn't work #39

Open
chippyash opened this issue May 15, 2018 · 2 comments
Open

Use of 'source=""' for select in 'multiple' doesn't work #39

chippyash opened this issue May 15, 2018 · 2 comments

Comments

@chippyash
Copy link
Collaborator

I have

           <multiple name="entries" min-entries="2">
            <tr>
                <td><select name="nominal"><options source="nominals"/></select></td>
                <td><input name="dr" type="number"></td>
                <td><input name="cr" type="number"></td>
                <td><button class="btn.del" value="Del"/></td>
            </tr>
            </multiple>

This fails to set the options correctly with $form->source('nominals', $this->nominals); and instead renders as

            <div class="multiple">
<div id="multiple152640179011218686025afb0afe01ff2" class="multiple-forms">
<div class="multiple-element" id="multiple15264017906284506685afb0afe020d3"/>
            <tr>
                <td><select name="entries[0][nominal]" source="nominals" >
</select>
</td><td><input step="any" type="number" name="entries[0][dr]" /></td><td><input step="any" type="number" name="entries[0][cr]" /></td><td><button class="btn.del" value="Del"/></td></tr>
<span class="multiple-remove"><a href="javascript:Formidable.removeInput('multiple15264017906284506685afb0afe020d3')">Remove</a><br /></span></div><div class="multiple-element" id="multiple152640179014166551895afb0afe02190"/>
            <tr>
                <td><select name="entries[1][nominal]" source="nominals" >
</select>
</td><td><input step="any" type="number" name="entries[1][dr]" /></td><td><input step="any" type="number" name="entries[1][cr]" /></td><td><button class="btn.del" value="Del"/></td></tr>
<span class="multiple-remove"><a href="javascript:Formidable.removeInput('multiple152640179014166551895afb0afe02190')">Remove</a><br /></span></div></div>
<div class="multiple-buttons"><script type="text/javascript">var multiple152640179011218686025afb0afe01ff2_code = "\n            <tr>\n                <td><select name=\"entries[{number}][nominal]\" source=\"nominals\" >\n<\/select>\n<\/td><td><input step=\"any\" type=\"number\" name=\"entries[{number}][dr]\" \/><\/td><td><input step=\"any\" type=\"number\" name=\"entries[{number}][cr]\" \/><\/td><td><button class=\"btn.del\" value=\"Del\"\/><\/td><\/tr>\n";
Formidable.multiple["multiple152640179011218686025afb0afe01ff2"] = 2;
</script><a href="javascript:Formidable.addInput('multiple152640179011218686025afb0afe01ff2', multiple152640179011218686025afb0afe01ff2_code);">Add</a></div></div>

instead of filling in the select options as expected.

I can see in 'Form.php'

    /**
     * Values sourcing
     */
    public function source($source, $data)
    {
        $sources = $this->parserData->getSources();

        $sources[$source]->source($data);
    }

This is only getting the sources for the outer form, not any multiples within it.

This could be changed to recurse into any multiples but then there is the consideration of what the javascript is going to do on row addition etc.

Can you suggest a sensible workaround, or point me in the right direction to create a PR?

Cheers

@Gregwar
Copy link
Owner

Gregwar commented May 15, 2018

I believe you are right, since multiple is actually handled with "sub-forms" the source should also be handled for them

Maybe another use case that is not handled and would require a source-improvement is having multiple fields having the same source, like:

Your favourite colour:
<select name="favourite_colour" source="colours"></select>

You second favourite colour:
<select name="second_favourite_colour" source="colours" /></select>

@chippyash
Copy link
Collaborator Author

ok - understood

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants