|
| 1 | +note |
| 2 | + description: "[ |
| 3 | + Represent attributes applicable to input type type=[number, range, date] |
| 4 | + The attributes: min, max, step. |
| 5 | + ]" |
| 6 | + date: "$Date$" |
| 7 | + revision: "$Revision$" |
| 8 | + EIS: "name=numeric attributes", "src=https://html.spec.whatwg.org/multipage/forms.html#common-input-element-attributes" |
| 9 | + |
| 10 | +class |
| 11 | + WSF_FORM_FIELD_WITH_NUMERIC_ATTRIBUTE |
| 12 | + |
| 13 | +inherit |
| 14 | + |
| 15 | + SHARED_HTML_ENCODER |
| 16 | + |
| 17 | + |
| 18 | +feature -- Access |
| 19 | + |
| 20 | + min: detachable READABLE_STRING_8 |
| 21 | + -- minimun value accepted by Current field. |
| 22 | + |
| 23 | + max: detachable READABLE_STRING_8 |
| 24 | + -- maximun value accepted by Current field. |
| 25 | + |
| 26 | + step: detachable READABLE_STRING_8 |
| 27 | + -- step is the increment that the value should adjust up or down, with the default step value being 1. |
| 28 | + |
| 29 | +feature -- Element Change |
| 30 | + |
| 31 | + set_min (a_val: INTEGER) |
| 32 | + -- Set `min' with `a_val'. |
| 33 | + do |
| 34 | + set_min_string (a_val.out) |
| 35 | + ensure |
| 36 | + min_set: attached min as l_min implies l_min.same_string (a_val.out) |
| 37 | + end |
| 38 | + |
| 39 | + set_max (a_val: INTEGER) |
| 40 | + -- Set `max' with `a_val'. |
| 41 | + do |
| 42 | + set_max_string(a_val.out) |
| 43 | + ensure |
| 44 | + max_set: attached max as l_max implies l_max.same_string (a_val.out) |
| 45 | + end |
| 46 | + |
| 47 | + set_step (a_val: REAL) |
| 48 | + -- Set `step' with `a_val'. |
| 49 | + do |
| 50 | + set_step_string (a_val.out) |
| 51 | + ensure |
| 52 | + step_set: attached step as l_step implies l_step.same_string (a_val.out) |
| 53 | + end |
| 54 | + |
| 55 | + set_min_string (a_val: READABLE_STRING_GENERAL) |
| 56 | + -- Set `min' with `a_val'. |
| 57 | + require |
| 58 | + is_valid_number: a_val.is_integer |
| 59 | + do |
| 60 | + if a_val.is_string_32 then |
| 61 | + min := html_encoder.encoded_string (a_val.as_string_32) |
| 62 | + elseif a_val.is_string_8 then |
| 63 | + min := a_val.as_string_8 |
| 64 | + end |
| 65 | + ensure |
| 66 | + min_set: attached min as l_min implies l_min.same_string_general (a_val) |
| 67 | + end |
| 68 | + |
| 69 | + set_max_string (a_val: READABLE_STRING_GENERAL) |
| 70 | + -- Set `max' with `a_val'. |
| 71 | + require |
| 72 | + is_valid_number: a_val.is_integer |
| 73 | + do |
| 74 | + if a_val.is_string_32 then |
| 75 | + max := html_encoder.encoded_string (a_val.as_string_32) |
| 76 | + elseif a_val.is_string_8 then |
| 77 | + max := a_val.as_string_8 |
| 78 | + end |
| 79 | + ensure |
| 80 | + max_set: attached max as l_max implies l_max.same_string_general (a_val) |
| 81 | + end |
| 82 | + |
| 83 | + set_step_string (a_val: READABLE_STRING_GENERAL) |
| 84 | + -- Set `step' with `a_val'. |
| 85 | + require |
| 86 | + is_valid_sequence: a_val.is_number_sequence or else a_val.is_real_sequence |
| 87 | + do |
| 88 | + if a_val.is_string_32 then |
| 89 | + step := html_encoder.encoded_string (a_val.as_string_32) |
| 90 | + elseif a_val.is_string_8 then |
| 91 | + step := a_val.as_string_8 |
| 92 | + end |
| 93 | + ensure |
| 94 | + step_set: attached step as l_step implies l_step.same_string_general (a_val) |
| 95 | + end |
| 96 | + |
| 97 | + |
| 98 | +feature {NONE} -- Conversion |
| 99 | + |
| 100 | + append_numeric_input_attributes_to (a_target: STRING) |
| 101 | + -- append numeric attributes to a_target, if any. |
| 102 | + do |
| 103 | + --min |
| 104 | + if attached min as l_min then |
| 105 | + a_target.append (" min=%"") |
| 106 | + a_target.append(l_min) |
| 107 | + a_target.append_character ('%"') |
| 108 | + end |
| 109 | + |
| 110 | + --max |
| 111 | + if attached max as l_max then |
| 112 | + a_target.append (" max=%"") |
| 113 | + a_target.append (l_max) |
| 114 | + a_target.append_character ('%"') |
| 115 | + end |
| 116 | + |
| 117 | + --step |
| 118 | + if attached step as l_step then |
| 119 | + a_target.append (" step=%"") |
| 120 | + a_target.append (l_step) |
| 121 | + a_target.append_character ('%"') |
| 122 | + end |
| 123 | + end |
| 124 | + |
| 125 | +end |
0 commit comments