def render(self, ctx, key, args, errors): charset = util.getPOSTCharset(ctx) converter = iformal.IStringConvertible(self.original) if errors: value = self._valueFromRequestArgs(charset, key, args) else: value = converter.fromType(args.get(key)) if value is None: value = iformal.IKey(self.noneOption).key() optionGen = inevow.IQ(self.template).patternGenerator('option') selectedOptionGen = inevow.IQ(self.template).patternGenerator('selectedOption') optionTags = [] selectOther = True if self.noneOption is not None: noneValue = iformal.IKey(self.noneOption).key() if value == noneValue: tag = selectedOptionGen() selectOther = False else: tag = optionGen() tag.fillSlots('value', noneValue) tag.fillSlots('label', iformal.ILabel(self.noneOption).label()) optionTags.append(tag) if self.options is not None: for item in self.options: if value == item: tag = selectedOptionGen() selectOther = False else: tag = optionGen() tag.fillSlots('value', item) tag.fillSlots('label', item) optionTags.append(tag) if selectOther: tag = selectedOptionGen() otherValue = value else: tag = optionGen() otherValue = '' tag.fillSlots('value', self.otherOption[0]) tag.fillSlots('label', self.otherOption[1]) optionTags.append(tag) tag = T.invisible[self.template.load(ctx)] tag.fillSlots('key', key) tag.fillSlots('id', render_cssid(key)) tag.fillSlots('options', optionTags) tag.fillSlots('otherValue', otherValue) return tag
def renderOptions(ctx, data): if self.noneOption is not None: yield T.option(value=iformal.IKey(self.noneOption).key())[iformal.ILabel(self.noneOption).label()] if data is None: return for item in data: optValue = iformal.IKey(item).key() optLabel = iformal.ILabel(item).label() optValue = converter.fromType(optValue) option = T.option(value=optValue)[optLabel] if optValue == value: option = option(selected='selected') yield option
def renderOptions(ctx, data): # A counter to assign unique ids to each input idCounter = itertools.count() if self.noneOption is not None: itemKey = iformal.IKey(self.noneOption).key() itemLabel = iformal.ILabel(self.noneOption).label() yield renderOption(ctx, itemKey, itemLabel, idCounter.next(), itemKey==value) if not data: return for item in data: itemKey = iformal.IKey(item).key() itemLabel = iformal.ILabel(item).label() itemKey = converter.fromType(itemKey) yield renderOption(ctx, itemKey, itemLabel, idCounter.next(), itemKey==value)
def processInput(self, ctx, key, args): charset = util.getPOSTCharset(ctx) value = self._valueFromRequestArgs(charset, key, args) value = iformal.IStringConvertible(self.original).toType(value) if self.noneOption is not None and value == iformal.IKey(self.noneOption).key(): value = None return self.original.validate(value)
def processInput(self, ctx, key, args): charset = util.getPOSTCharset(ctx) value = args.get(key, [''])[0].decode(charset) value = iformal.IStringConvertible(self.original).toType(value) if self.noneOption is not None and \ value == iformal.IKey(self.noneOption).key(): value = None return self.original.validate(value)
def renderer(ctx, options): # loops through checkbox options and renders for n,item in enumerate(options): optValue = iformal.IKey(item).key() optLabel = iformal.ILabel(item).label() optValue = converter.fromType(optValue) optid = render_cssid(key, n) checkbox = T.input(type='checkbox', name=key, value=optValue, id=optid) if optValue in values: checkbox = checkbox(checked='checked') if disabled: checkbox = checkbox(class_='disabled', disabled='disabled') yield checkbox, T.label(for_=optid)[optLabel], T.br()