def present(self, **kwargs: Any) -> XMLContent: form: _FormPresenter = kwargs['form'] attributes = self._attributes if 'autofocus' in attributes: attributes = dict(attributes) wantFocus = attributes.pop('autofocus') if not isinstance(wantFocus, bool): raise TypeError(type(wantFocus)) else: wantFocus = True if attributes.get('disabled', False): wantFocus = False name = cast(Optional[str], attributes.get('name')) focus = form.addControl(name, wantFocus) if name is not None: form.addClearCode(f'inputs.{name}.value = "";') if 'value' not in attributes: value = _argValue(kwargs['formArgs'], name) if isinstance(value, (Enum, str, int)): attributes = dict(attributes, value = value) elif value is not None: raise TypeError(type(value)) return xhtml.input(autofocus=focus, **attributes)
def iterCloseItems(self, args: Optional[PageArgs]) -> XMLContent: if args is not None: controls = self.__controls for key, values in args.externalize(): if key not in controls: for value in values: yield xhtml.input(type='hidden', name=key, value=value) yield script[ self.__iterScriptFragments() ].present()
def present(self, **kwargs: object) -> XMLContent: form = cast(_FormPresenter, kwargs['form']) attributes = self._attributes name = cast(Optional[str], attributes.get('name')) if name is None: return None form.addControl(name, False) if 'value' in attributes: return xhtml.input(**attributes) else: return None
def iterRows(self, **kwargs: object) -> Iterator[XMLContent]: form = cast(_FormPresenter, kwargs['form']) formId = form.id name = self.name active = self.getActive(**kwargs) for index, item in enumerate(self.iterOptions(**kwargs)): focus = index == 0 and form.addControl(name, True) key = cast(str, item[0]) box = xhtml.input( type = 'radio', tabindex = 1, name = name, value = key, checked = key == active, autofocus = focus ) yield row( # Note: While clicking the label will activate the button, # the JavaScript reacts to the entire row. onclick=f"document.forms.{formId}['{name}'][{index:d}]" '.checked=true', class_='clickable' )[ self.formatOption(box, item[1:]) ]
def iterRows(self, **kwargs: object) -> Iterator[XMLContent]: form = cast(_FormPresenter, kwargs['form']) active = self.getActive(**kwargs) first = True for key, cells in self.iterOptions(**kwargs): if first: focus = form.addControl(self.name, True) first = False else: focus = False boxCell: XMLContent = cell(class_='clickable', onclick='toggleRow(event)')[ xhtml.label[ xhtml.input( type = 'checkbox', tabindex = 1, name = self.name, value = key, checked = key in active, autofocus = focus ), ' ', cells[0] ] ] yield (boxCell,) + tuple(cells[1 : ])
def present(self, **kwargs: Any) -> XMLContent: form: Optional[_FormPresenter] = kwargs.get('form') attributes = self._attributes name = cast(Optional[str], attributes.get('name')) if form is None: focus = False else: focus = form.addControl(name, True) if 'checked' not in attributes and name is not None: value = _argValue(kwargs['formArgs'], name) if isinstance(value, bool): checked = value elif isinstance(value, frozenset): checked = attributes['value'] in value else: raise TypeError(type(value)) if checked: attributes = dict(attributes, checked=True) box = xhtml.input(type='checkbox', autofocus=focus, **attributes) label = tuple(self._presentContents(**kwargs)) return xhtml.label[ box, label ] if label else box