Increasing the number of character entries

Can I unlimited or increase the number of characters entered in the field farm area text?(for exp Ican enter 1000 characters, i want to increase to 2000)

note:number of values ​​unlimited selected

1 Like

Ah yes, that is a limitation of the form element, but not of the underlying database (since it can be used to reference multiple areas). Which form are you seeing this in, specifically? There are a few places in farmOS where we have an auto-complete area reference field.

In some ways this is already “fixed” in the farmOS 2.x branch, because areas are now assets, and we will be using a more advanced selection interface (not an autocomplete field). But I might be able to point you in the right direction to override the limitation in your 1.x instance.

For example, here I entered F10000093 last field. I want to continue as F10000094, F10000095. But it won’t let me write. I think I reached the maximum number of characters. So I want to increase the number of characters here.

[image]

1 Like

What is the URL of the page you are looking at? I can’t tell from the screenshot. This field appears in a few different forms in farmOS, and each may come from different code.

q=log/add/farm_observation -->location tab–>areas

Ok, so that is controlled by the Drupal core Field API, which means you will probably need to create use hook_field_widget_form_alter() in a custom module to modify it.

https://api.drupal.org/api/drupal/modules!field!field.api.php/function/hook_field_widget_form_alter/7.x

Whether I will create the hook_field_widget_form_alter () function under the observation module or it should be under the custom module. I created it but it didn’t work.

the code i use is as below

function farm_log_observation_field_widget_form_alter(&$element, FormStateInterface $form_state, $context) {
$field_definition = $context[‘items’]->getFieldDefinition();
if ($field_definition->getType() == ‘link’) {
if ($field_definition->get(‘field_name’) == ‘field_farm_area’) {
$element[‘fields’][‘field_farm_area’][‘alter’][‘max_length’] = ‘1400’;
}
}
}

1 Like

Whether I will create the hook_field_widget_form_alter () function under the observation module or it should be under the custom module

Always put custom code in a custom module. If you alter any of the core farmOS modules, and then upgrade farmOS, all your customizations will be lost. This is because the update process replaces all core code with the newer version, which will not include your modifications.

This reasoning is outlined in Drupal’s “Do Not Hack Core” best practice: http://drupal.org/best-practices/do-not-hack-core

I created it but it didn’t work.

Do you have access to a debugger like XDebug? That’s the best way to figure out why code isn’t working.

it does not give an error but I cannot increase maxlength. Is there any similar example in farmos?

$element[‘fields’][‘field_farm_area’][‘alter’][‘max_length’] = ‘1400’;

The structure of this looks weird to me - I don’t think it’s correct. If you don’t have access to a debugger like XDebug, another option is to install the Devel module: https://drupal.org/project/devel

This module provides a dpm() function that can be used to print out the contents of a variable in a way that’s easy to inspect. If you put dpm($element) just above that line it might give you a sense of what it needs to look like.

Here is the Drupal 7 Form API Reference as well: https://api.drupal.org/api/drupal/developer!topics!forms_api_reference.html/7.x

The #maxlength property is probably what you’re looking for (unless this widget does things differently): https://api.drupal.org/api/drupal/developer!topics!forms_api_reference.html/7.x#maxlength