Skip Navigation

[Resuelto] I need Validation for a Checkbox field

This support ticket is created hace 5 años, 10 meses. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 -
- 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 -

Supporter timezone: Europe/London (GMT+00:00)

This topic contains 1 respuesta, has 2 mensajes.

Last updated by Nigel hace 5 años, 10 meses.

Assisted by: Nigel.

Autor
Mensajes
#907196

I need to do exactly what this guy did: https://toolset.com/forums/topic/cant-validate-checkboxes/ except that I am not using CRED form.

Is it possible to force validation of a checkbox field in my Post Fields area or via a code snippet like the one in the linked thread?

Thanks,

Marcus

#907317

Nigel
Supporter

Languages: Inglés (English ) Español (Español )

Timezone: Europe/London (GMT+00:00)

Hi Marcus

You need this for a checkboxes field (plural), right? Where at least one of the checkboxes must be checked.

That's not too difficult to do with CRED forms, as described in the other thread, as you can use the validation hook of the CRED API.

There is no equivalent hook to do the same in core WordPress (but it might be added: https://core.trac.wordpress.org/ticket/43019).

The only alternative I can think of is to write a bespoke JavaScript solution to disable submitting the form until one of the checkboxes has been checked.

For information about the best way to enqueue JS on the admin post edit screen for custom post types, see this: https://wordpress.stackexchange.com/a/243738/35739

The JS you write itself will want setting up something like this:

( function( $ ) {
	$( document ).ready( function(){
		// Your code here

	});
})( jQuery );

You can use the jQuery change function to trigger some code when the checkboxes fields are checked (hidden link).

Writing such code is outside our support policy, I'm afraid, and the queue is too busy for me to go much further than the above advice.

Sorry I can't be more helpful.

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.