RFC / POC: Repeatable Settings Fields #70
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hi Tareq, thanks for writing this I found it really helped speed up creating a WP plugin recently for a client, and a heap easier to work with than the existing WP settings API!
This PR is really not right to merge, it's more a POC or discussion starter about introducing repeatables as field type. If it's of interest I will refine so it can be merged.
Overview
This PR introduces a new field type repeatable created exactly the same was as existing field types. A repeatable is simply a container for other fields of the standard field types that are in the children array of the repeatable. See below:
This would show up in the settings page as:
On the form submit the data is json encoded into a hidden input field that matches the top level name of the repeatable type. In this case repeatable.
On the form display the JSON encoded option is parsed and the data used to populate the children element array.
The Add button will add a new row and the X button will delete an existing row.
Work to Be Done
If there's interest in adding this feature the main work that still needs to be done is to move fields other than text into the repeatable when creating the child fields for the markup.
Currently the only field that works as a repeatable child is a text field
To do this properly I would probably slightly modify the existing callback_type methods to allow their use in the repeatable as well as stand alone fields.
I would also like to remove some of the inline javascript and move into the jquery.repeatable.js file.