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

Custom field types extendable by plugins #293

Closed
herregroen opened this issue Jan 15, 2016 · 2 comments
Closed

Custom field types extendable by plugins #293

herregroen opened this issue Jan 15, 2016 · 2 comments

Comments

@herregroen
Copy link

I was looking through the source code and noticed that the list of available custom field types seems to be hardcoded.

Perhaps adding functionality to allow plugins to add to this list could be a desirable feature?

For example, a simple use case would be postal codes. Considering formats vary between countries a single input would either be very complex or fail to validate correctly depending on country. Allowing a plugin to define a postal code custom field could allow country-specific validations and functionality whilst keeping the field relatively simple.

Other use-cases could include custom fields to interact with third-party APIs, allowing very specific validations or having certain javascript inputs.

I'd image something like a CustomFieldType class whose descendants are automatically added and each defining standard options the input uses ( required, multiple etc. ), the partial to use when editing a custom field group, how to render the input in a post form, how to validate submitted values and perhaps some callbacks when the field is set.

If desirable I could see about creating a PR for this. Would take some time though as I'd have to get more familiar with the codebase first.

@owen2345
Copy link
Owner

@herregroen it would be great!

@owen2345
Copy link
Owner

Version 2.3.x added the support, samples:
Simple field: https://gist.github.com/owen2345/b9cb0437b338ac712be59f6a7a7ebf70
Complex field: https://gist.github.com/owen2345/fdec8eb47db6db91a76c05827bc64c5b

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

3 participants