selection input widget useful list selection field implements the oninput event. https://developer.mozilla.org/en-US/docs/Web/HTML/Element/datalist
| 3560 | |
| 3561 | |
| 3562 | class SelectionInput(Input): |
| 3563 | """ selection input widget useful list selection field implements the oninput event. |
| 3564 | https://developer.mozilla.org/en-US/docs/Web/HTML/Element/datalist |
| 3565 | """ |
| 3566 | |
| 3567 | @property |
| 3568 | @editor_attribute_decorator("WidgetSpecific", '''Defines the actual value for the widget.''', str, {}) |
| 3569 | def attr_value(self): return self.attributes.get('value', '0') |
| 3570 | @attr_value.setter |
| 3571 | def attr_value(self, value): self.attributes['value'] = str(value) |
| 3572 | |
| 3573 | @property |
| 3574 | @editor_attribute_decorator("WidgetSpecific", '''Defines the datalist.''', str, {}) |
| 3575 | def attr_datalist_identifier(self): |
| 3576 | return self.attributes.get('list', '0') |
| 3577 | @attr_datalist_identifier.setter |
| 3578 | def attr_datalist_identifier(self, value): |
| 3579 | if isinstance(value, Datalist): |
| 3580 | value = value.identifier |
| 3581 | self.attributes['list'] = value |
| 3582 | |
| 3583 | @property |
| 3584 | @editor_attribute_decorator("WidgetSpecific", '''Defines the view type.''', 'DropDown', {'possible_values': ('text', 'search', 'url', 'tel', 'email', 'date', 'month', 'week', 'time', 'datetime-local', 'number', 'range', 'color')}) |
| 3585 | def attr_input_type(self): return self.attributes.get('type', 'text') |
| 3586 | @attr_input_type.setter |
| 3587 | def attr_input_type(self, value): self.attributes['type'] = str(value) |
| 3588 | |
| 3589 | def __init__(self, default_value="", input_type="text", *args, **kwargs): |
| 3590 | """ |
| 3591 | Args: |
| 3592 | selection_type (str): text, search, url, tel, email, date, month, week, time, datetime-local, number, range, color. |
| 3593 | kwargs: See Widget.__init__() |
| 3594 | """ |
| 3595 | super(SelectionInput, self).__init__(input_type, default_value, *args, **kwargs) |
| 3596 | |
| 3597 | self.attributes[Widget.EVENT_ONCHANGE] = \ |
| 3598 | "var params={};params['value']=document.getElementById('%(emitter_identifier)s').value;" \ |
| 3599 | "remi.sendCallbackParam('%(emitter_identifier)s','%(event_name)s',params);"% \ |
| 3600 | {'emitter_identifier':str(self.identifier), 'event_name':Widget.EVENT_ONCHANGE} |
| 3601 | |
| 3602 | @decorate_set_on_listener("(self, emitter, value)") |
| 3603 | @decorate_event_js("""var params={}; |
| 3604 | params['value']=this.value; |
| 3605 | remi.sendCallbackParam('%(emitter_identifier)s','%(event_name)s',params);""") |
| 3606 | def oninput(self, value): |
| 3607 | self.disable_update() |
| 3608 | self.set_value(value) |
| 3609 | self.enable_update() |
| 3610 | return (value, ) |
| 3611 | |
| 3612 | def set_value(self, value): |
| 3613 | self.attr_value = value |
| 3614 | |
| 3615 | def get_value(self): |
| 3616 | """ |
| 3617 | Returns: |
| 3618 | str: the actual value |
| 3619 | """ |