• Resolved bmontgomery

    (@bmontgomery)


    Hello,

    I need to add a custom field of type “date”.
    But I saw in /includes/defaults.php that this type doesn’t exist.
    How could I do this ?
    Is it possible to add new custom field types ?

    Could you please help me ?

Viewing 1 replies (of 1 total)
  • Plugin Author Greg Winiarski

    (@gwin)

    It is possible to create new field types you need a function which will render this field and adverts_form_add_field() call that will register the field

    
    function my_custom_field( $field ) {
        
        $attr = array(
            "type" => "date",
            "name" => $field["name"],
            "id" => $field["name"],
            "value" => isset($field["value"]) ? $field["value"] : "",
            "placeholder" => isset($field["placeholder"]) ? $field["placeholder"] : null,
            "class" => isset($field["class"]) ? $field["class"] : null
        );
        
        if( isset( $field["attr"] ) && is_array( $field["attr"] ) ) {
            foreach( $field["attr"] as $key => $value ) {
                if( $value !== null && is_scalar( $value ) ) {
                    $attr[$key] = $value;
                }
            }
        }
        
        $html = new Adverts_Html( "input", $attr );
        
        echo $html->render();
    }
    adverts_form_add_field("my_custom_field", array(
        "renderer" => "my_custom_field",
        "callback_save" => "adverts_save_single",
        "callback_bind" => "adverts_bind_single",
    ));
    

    Then when registering the field use "type" => "my_custom_field"

Viewing 1 replies (of 1 total)
  • The topic ‘custom field date’ is closed to new replies.