BUG: Using new HTML attributes for a field doesn’t work
I want this input to be of type=”number” and with min=”0.50″ and step=”0.25″, but it doesn’t work. The field stays as an integer and can allow negative numbers. Why is this happening?
public function ask_form_amount_field($args, $editing){
if(wp_count_terms('question_amount_field') == 0)
return $args; //Taxonomy stuff?
global $editing_post;
if($editing){
$amount_field = get_the_terms( $editing_post->ID, 'question_amount_field' );
$amount_field = $amount_field[0]->term_id;
} //More things purely related to taxonomy, it seems.
$args['fields'][] = array(
'name' => 'amount_field',
'label' => __('Amount field label', 'amount_field_for_anspress'),
'type' => 'number',
'value' => ( $editing ? $amount_field : sanitize_text_field(@$_POST['amount_field'] )),
'taxonomy' => 'question_amount_field',
'orderby' => ap_opt('form_amount_field_orderby'),
'desc' => __('Enter the amount you wish to tip someone for fulfilling your request.', 'amount_for_anspress'),
'order' => 7,
'min' => 0.50,
'step' => 0.25
);
return $args;
}In another question you suggested to simply paste into theme -> functions.php (link –> https://anspress.io/questions/question/which-php-files-do-i-need-to-modify-in-order-to-add-a-new-field-in-the-question-form/?show_answer=6983&ap_notification_read=184825#answer_6983). But instead I made this project into an extension for anspress (similar to how categories-for-anspress is an extension). I am using the lines of code below in my Find-Do-For-Anspress class.
add_action( ‘ap_ask_form_fields’, array( $this, ‘ask_form_amount_field’ ), 10, 2 );
add_action( ‘ap_ask_fields_validation’, array( $this, ‘ap_ask_fields_validation’ ) );
add_action( ‘ap_processed_new_question’, array( $this, ‘after_new_question’ ), 0, 2 );
add_action( ‘ap_processed_update_question’, array( $this, ‘after_new_question’ ), 0, 2 );
public function ap_ask_fields_validation($args){
if(wp_count_terms(‘question_amount_field’) == 0)
return $args;
$args[‘amount_field’] = array(
//’sanitize’ => array(‘only_int’), THIS LINE IS COMMENTED OUT
‘validate’ => array(‘required’),
);
return $args;
}
public function after_new_question($post_id, $post)
{
global $validate;
if(empty($validate))
return;
$fields = $validate->get_sanitized_fields();
if(isset($fields[‘amount_field’]))
$amount = wp_set_post_terms( $post_id, $fields[‘amount_field’], ‘question_amount_field’ );
}
Just try input as text field instead of number
So then is it possible to add numeric validation using javascript?
How you are processing the field?