MCPcopy Create free account
hub / github.com/cryptii/cryptii / renderField

Method renderField

src/View/Field/Enum.js:71–140  ·  view source on GitHub ↗

* Renders field. * @protected * @return {?HTMLElement}

()

Source from the content-addressed store, hash-verified

69 * @return {?HTMLElement}
70 */
71 renderField () {
72 // Collect labels
73 const elementLabels = this.getModel().getElementLabels()
74 const elementDescriptions = this.getModel().getElementDescriptions()
75
76 // Prepare field
77 const $field = super.renderField()
78 $field.classList.remove('field__field')
79 $field.classList.add('field-enum__field')
80
81 if (this.getStyle() === 'radio') {
82 this._$$radio = []
83
84 // Prepare radio group
85 const $radioGroup = View.createElement('div', {
86 className: 'field-enum__options',
87 role: 'radiogroup',
88 id: this.getId()
89 })
90
91 $field.appendChild($radioGroup)
92
93 // Render each option
94 elementLabels.forEach((label, index) => {
95 const optionId = `${this.getId()}-${index + 1}`
96
97 const $radio = View.createElement('input', {
98 type: 'radio',
99 className: 'field-enum__option-radio',
100 id: optionId,
101 onChange: this.valueDidChange.bind(this),
102 name: this.getId()
103 })
104
105 const $option = View.createElement('div', {
106 className: 'field-enum__option'
107 }, [
108 $radio,
109 View.createElement('label', {
110 htmlFor: optionId,
111 className: 'field-enum__option-label'
112 }, label)
113 ])
114
115 this._$$radio.push($radio)
116 $radioGroup.appendChild($option)
117 })
118 } else {
119 // Create option for each element
120 const $options = elementLabels.map((label, index) =>
121 View.createElement('option', {
122 value: index,
123 title: elementDescriptions[index] || ''
124 }, label))
125
126 // Create select element
127 this._$select = View.createElement('select', {
128 className: 'field-enum__select',

Callers

nothing calls this directly

Calls 8

getStyleMethod · 0.95
getElementLabelsMethod · 0.80
createElementMethod · 0.80
focusMethod · 0.80
blurMethod · 0.80
getModelMethod · 0.45
getIdMethod · 0.45

Tested by

no test coverage detected