I use hook_form_alter()
to alter a field.
function mymodule_form_alter(&$form, &$form_state) {
if ($form['#id'] == 'my_form') {
$form['my_field']['#value'] = 'New value';
}
}
It changes the field value to new value, but the problem is that, as soon as I enable this module, the JavaScript on forms stops working. For example drop-downs, autocomplete, AJAX no longer works.
I cant understand what cause this.
$form['#id']
, but that is another matter.$form['my_field']['#value']
, you should check$form['my_field']
has been set.