Answer the question
In order to leave comments, you need to log in
How to prevent editing a field if it is already filled?
I've been suffering for a couple of days now. It is necessary to forbid editing the "Link to term" field if the field already has a value. But for some reason the module does not want to work. No way. No errors in the logs, but that's all.
Here is the module itself:
function field_acces_if_form_user_profile_form_alter(&$form, &$form_state, $form_id) {
$field_name = 'field_user_company_name'; // Машинное имя поля
$langcode = LANGUAGE_NONE; // Код языковой версии
if (isset($form[$field_name][$langcode])) {
$items = element_children($form[$field_name][$langcode]);
foreach ($items as $i) {
// Если значение поля заполнено
if ($form[$field_name][$langcode][$i]['value']['#default_value']) {
$form[$field_name]['#disabled'] = TRUE; // Выключаем поле
break; // И выходим из цикла
}
}
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question