1

I have a views display that lists out content that meets a criteria defined by an exposed form. One of the filters is 2 values which a content attribute must be between. In views, I can define this as a default min and max value.

I would like to get these default values out as data attributes on the form fields for some javascript validation, and therefore will need to be able to get these as twig variables in the form element template, or set these as attributes in the form element preprocess.

The inputs initially have the value of the default min and max, but as soon as these are changed there is no way I can see to access the defaults.

How can I do this?

0
function MYTHEME_preprocess_input(&$variables) {
  if (isset($variables['element']['#default_value'])){
    $variables['attributes']['data-default-value'] = $variables['element']['#default_value'];
  }
}
|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.