What do I need to create a custom form widget? I used hook_field_widget_info() and hook_field_widget_form() to create a new widget for the user reference module. The problem is when I select a value in content edit form using my widget, selected value is not shown in node display page. Also when I go back to the edit form, my selected value is not the default value(is not saved).

Does it need anything else to work properly?




function mymodule_field_widget_info() {
    return array(
       'custom_user_widget' => array(
            'label' => 'Custom user widget',
            'field types' => array('user_reference'),
            'behaviors' => array(
                'multiple values' => FIELD_BEHAVIOR_DEFAULT,
                'default value' => FIELD_BEHAVIOR_DEFAULT,
            ),
        ),
    );
}
function mymodule_field_widget_form(&$form, &$form_state, $field, $instance, $langcode, $items, $delta, $element) {
    if ($instance['widget']['type'] == 'custom_user_widget') {
        $element['uid'] = array(
            '#type' => 'select',
            '#options' => array(1=>'a', 2=>'b', 3=>'c'),
            '#title' => t('Username')
        );
        return $element;
    }
}
You need to implement the "view hook":

/**
* Implements hook_field_formatter_view().
*/
function mymodule_field_widget_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) {
    $element = array();

    switch ($display['type']) {
    case 'custom_user_widget':
    $element[] = 'add here what you want to show';
    break;
    }
    return $element;
}