Home › Forums › Front-end Issues › Disabled and required Post Object field fails validation › Reply To: Disabled and required Post Object field fails validation
Hi @hube2,
Thanks, this was helpful.
I need to rephrase my issue and explain it a bit better.
I need to show an ACF form on the front-end to add/edit posts of custom type “Application”. Fields “Job” and “Company” are pre-selected and must be always blocked or marked as read-only (user can’t change them), but I don’t know how I can do it with a Post Object field type (and whether it’s possible at all).
I tried smth like this:
acf.add_action('select2_init', function($input, args, settings, $field){
if ($field.hasClass('application-job')) {
args.disabled = true;
settings.disabled = true;
args.readonly = true;
settings.readonly = true;
}
});
Unfortunately, none of this worked.
On the back-end fields “Job” and “Company” must be enabled and required so an administrator cannot leave them empty.
If you have an idea how I can reach this goal, please share 🙂
As the last possible (alternative) solution I can do the following:
Create another fields group, where both Post Object fields are replaced by Text fields. Text fields can be made read-only very easily. This field group will be shown only on the front-end.
And my task would be just to synchronize them on post update.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.