<commit_before>package EnsEMBL::Web::Form::Element;

### How to add new element class?
### 1. Create the required package (class) with name Web::Form::Element::$new_element
### 2. Inherit from one of the existing Element class in Web::Form::Element::* (in this folder or any plugins)
###    (eg. as in Web::Form::Element::String)
###    OR
###    Inherit from the required element class in DOM::Node::Element::* and this class respectively (MI)
###    (eg. as in Web::Form::Element::String)
### 3. Create a subroutine configure() in the new class which reads the params (check this class's configure method) and
###    configures the element accordingly
### 4. Add a key with a "form-element-$short_name" with value equal to the new class's name to &map_element_class in this class
###    (eg. 'form-element-dropdown' => 'EnsEMBL::Web::Form::Element::Dropdown') "form-element-" is always the prefix
###    This short name will be used as argument in ->dom::create_element().
### 5. DONE - call dom::create_element method to create this element instead using the constructor straight away.
###           call $new_element->configure() immidiately after to configure the element

use strict;

use constant {
  CSS_CLASS_REQUIRED  => 'required',
  CSS_CLASS_OPTIONAL  => 'optional',
};

sub configure {
  ## Configures the element according to the parameters
  ## Does all the set_attribute, append_child and other DOM manipulation (depending upon params) after the element is created 
  ## Override this in the child class
  ## @params HashRef of params required for configuring the element
  ##  - type            Type of element - should match with one of keys in &map_element_class leaving the prefix
  ##  - id              Id attribute - if not options, this also goes in 'for' attribute of label.
  ##  - name            Name attribute
  ##  - value           Value attribute for text type field, selected/checked value for checkbox/radio/select -  can be an ArrayRef for multiple values
  ##  - shortnote       A short text to go just right the text/password/file or select.
  ##  - inline          Flag stating whether checkbox/radio buttons are to be disaplayed in a horizontal line in case of checklist/radiolist
  ##  - size            Size attribute for text input, password input or select.
  ##  - selectall       Flag to tell whether or not we need a selectall checkbox in case of a checklist
  ##  - values          ArrayRef of Hashref for all options checkbox, radio or select with following keys each
  ##    - id            Id attribute for the option
  ##    - value         Value of the option
  ##    - name          name attribute incase of checkboxes. This will override the default name attribute (the one for the whole list)
  ##    - caption       InnerHTML of the option OR label for checkboxes and radio buttons
  ##    - group         If option needs to go in any <optgroup> in case of <option> or a sub heading in case of checkbox/radio
  ##    - is_plain_text Flag kept on if html encoding needs to be done to the caption
  ##  - no_input        Flag to prevent a hidden input automatically being added from NoEdit element
  ##  - class           Class attribute (space seperated string for multiple classes) - goes to all the sub elements (inputs, selects, textarea)
  ##  - wrapper_class   Class attribute for the wrapper (if there's any wrapper - eg. in checklist etc)
  ##  - option_class    Class attribute for all the options (in case of a dropdown)
  ##  - disabled        Flag for disabled attribute<commit_msg>wrapper_id key added<commit_after>package EnsEMBL::Web::Form::Element;

### How to add new element class?
### 1. Create the required package (class) with name Web::Form::Element::$new_element
### 2. Inherit from one of the existing Element class in Web::Form::Element::* (in this folder or any plugins)
###    (eg. as in Web::Form::Element::String)
###    OR
###    Inherit from the required element class in DOM::Node::Element::* and this class respectively (MI)
###    (eg. as in Web::Form::Element::String)
### 3. Create a subroutine configure() in the new class which reads the params (check this class's configure method) and
###    configures the element accordingly
### 4. Add a key with a "form-element-$short_name" with value equal to the new class's name to &map_element_class in this class
###    (eg. 'form-element-dropdown' => 'EnsEMBL::Web::Form::Element::Dropdown') "form-element-" is always the prefix
###    This short name will be used as argument in ->dom::create_element().
### 5. DONE - call dom::create_element method to create this element instead using the constructor straight away.
###           call $new_element->configure() immidiately after to configure the element

use strict;

use constant {
  CSS_CLASS_REQUIRED  => 'required',
  CSS_CLASS_OPTIONAL  => 'optional',
};

sub configure {
  ## Configures the element according to the parameters
  ## Does all the set_attribute, append_child and other DOM manipulation (depending upon params) after the element is created 
  ## Override this in the child class
  ## @params HashRef of params required for configuring the element
  ##  - type            Type of element - should match with one of keys in &map_element_class leaving the prefix
  ##  - id              Id attribute - if not options, this also goes in 'for' attribute of label.
  ##  - wrapper_id      Id attribute for the wrapper div if present (eg. in Checklist)
  ##  - name            Name attribute
  ##  - value           Value attribute for text type field, selected/checked value for checkbox/radio/select -  can be an ArrayRef for multiple values
  ##  - shortnote       A short text to go just right the text/password/file or select.
  ##  - inline          Flag stating whether checkbox/radio buttons are to be disaplayed in a horizontal line in case of checklist/radiolist
  ##  - size            Size attribute for text input, password input or select.
  ##  - selectall       Flag to tell whether or not we need a selectall checkbox in case of a checklist
  ##  - values          ArrayRef of Hashref for all options checkbox, radio or select with following keys each
  ##    - id            Id attribute for the option
  ##    - value         Value of the option
  ##    - name          name attribute incase of checkboxes. This will override the default name attribute (the one for the whole list)
  ##    - caption       InnerHTML of the option OR label for checkboxes and radio buttons
  ##    - group         If option needs to go in any <optgroup> in case of <option> or a sub heading in case of checkbox/radio
  ##    - is_plain_text Flag kept on if html encoding needs to be done to the caption
  ##  - no_input        Flag to prevent a hidden input automatically being added from NoEdit element
  ##  - class           Class attribute (space seperated string for multiple classes) - goes to all the sub elements (inputs, selects, textarea)
  ##  - wrapper_class   Class attribute for the wrapper (if there's any wrapper - eg. in checklist etc)
  ##  - option_class    Class attribute for all the options (in case of a dropdown)
  ##  - disabled        Flag for disabled attribute
{'fraction_non_alphanumeric': 0.07953281423804227, 'fraction_numerical': 0.0013904338153503894, 'mean_word_length': 3.136285221391604, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2630173', 'n_tokens_mistral': 1863, 'n_tokens_neox': 1808, 'n_words': 913}