Home Forums WC Vendors Pro Support Applying Character Limits to Custom Fields in the Product Form

NOTICE: We've Moved to a Ticket System for Support

As of August 31, 2017 (12am EST) our support forums will be retired (read-only), and we will be moving to a support ticket system.  This will allow us to better organize and answer support requests, and provide a more personalized experience as we assist our customers.

For the time being, we will leave our forums open for reading and learning while we work on creating a more robust Knowledge Base for everyone to use.

If you are a WC Vendors Pro customer please open a support ticket here. 

If you are a WC Vendors user please open a support ticket on the Wordpress.org forums.

The information on this forum is outdated and in most instances no longer relevant. Please be sure to check our documentation for the most up to date information.

https://docs.wcvendors.com/

Thank you to all of our customers!

 

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #37707
    Daniel
    Participant

    Hello,

    Wondering if its possible to apply character limits to custom fields on the product form? We’re wanting specific character limits, and the closest thing we’ve found is this thread: https://www.wcvendors.com/help/topic/request-limit-product-name-to-99-characters/, which doesn’t clarify whether it’s possible in a relatively simple way.

    Here’s what we’ve tried to do:

    			WCVendors_Pro_Form_Helper::input( array(  
    				 'type'      => 'text',
    				 'post_id'   => $object_id, 
    				 'id'     => 'wcv_custom_product_includes_0', 
    				 'placeholder'   => __( 'Included', 'wcvendors-pro' ), 
    				 'desc_tip'    => 'true',
    				 'maxlength' => '120' 
    			) );

    The maxlength attribute doesn’t do anything, so clearly that’s not the way to go. Any ideas?

    Thanks for your help!

    #37981
    Jamie
    Keymaster

    Hello,

    You’re very close. When wanting to add validation rules you need to specify them as custom attributes in your field like this:

    WCVendors_Pro_Form_Helper::input( array(  
    				 'type'      => 'text',
    				 'post_id'   => $object_id, 
    				 'id'     => 'wcv_custom_product_includes_0', 
    				 'placeholder'   => __( 'Included', 'wcvendors-pro' ), 
    				 'desc_tip'    => 'true',
    				 'custom_attributes' => array( 
    		 			'data-rules' => 'max_length[120]', 
    
    		 		)
    			)
    ) );

    cheers,

    Jamie

    #38037
    Daniel
    Participant

    Thanks Jamie, this is working. I do have another couple of questions however:

    1) if I have a field that needs a character limit and is required, how do I do that? Is it possible to make data-rules an array like this:

    			WCVendors_Pro_Form_Helper::input( array(  
    				 'type'      => 'text',
    				 'post_id'   => $object_id, 
    				 'id'     => 'wcv_custom_product_language_spoken', 
    				 'label'    => __( 'Language Spoken by Staff', 'wcvendors-pro' ), 
    				 'placeholder'   => __( 'Language Spoken by Staff', 'wcvendors-pro' ), 
    				 'desc_tip'    => 'true', 
    				 'description'   => __( 'Language Spoken by Staff', 'wcvendors-pro' ),
    				 'custom_attributes' => array( 
    				 	'multiple' => 'multiple',
    				 	'data-rules' => array (
    						'max_length[120]',
    						'required'))				  
    			) );

    I’m testing this now, and it doesn’t seem to be working. It’s not throwing the error for the required field. Let me know how I’d do this, and how I’d specify the errors for both cases.

    In a more general sense, is there documentation anywhere on how to set all the options of the input arrays for these fields? I can’t find any reference on this site beyond the single case example in the “Adding a Custom Field for Products” KnowledgeBase article; I’ve spent a couple hours getting familiar with WP form inputs in general, but it looks like WC Vendors & Pro overlay that functionality and have a language of their own. A reference, if it exists would be great to have access to, and if it doesn’t would be a fabulous thing to create and share.

    Thanks!

    #38173
    Jamie
    Keymaster

    Hello,

    You just need to combine the rules using a |. So the line : ‘data-rules’ => ‘max_length[120]’, turns into ‘data-rules’ => ‘max_length[120]|required’,

    cheers,

    Jamie.

    #38233
    Daniel
    Participant

    Ok, that’s working, but one further question. We still need to differentiate the two data-error handlers – one for not filling in the required field, the other for going over 120 characters.

    Here’s what we currently have, and the error handlers are not working as intended.

    			// Language Spoken Field
    			WCVendors_Pro_Form_Helper::input( array(  
    				 'type'      => 'text',
    				 'post_id'   => $object_id, 
    				 'id'     => 'wcv_custom_product_language_spoken', 
    				 'label'    => __( 'Language Spoken by Staff', 'wcvendors-pro' ), 
    				 'placeholder'   => __( 'Language Spoken by Staff', 'wcvendors-pro' ), 
    				 'desc_tip'    => 'true', 
    				 'description'   => __( 'Language Spoken by Staff', 'wcvendors-pro' ),
    				 'custom_attributes' => array( 
    				 	'multiple' => 'multiple',
    				 	'data-rules' => 'max_length[120]|required',
    					'data-error' => __( 'Maximum 120 Characters|This field is required.', 'wcvendors-pro' ))					  
    			) );

    Thanks!

Viewing 5 posts - 1 through 5 (of 5 total)
  • The forum ‘WC Vendors Pro Support’ is closed to new topics and replies.