Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1# encoding: utf-8 

2from builtins import zip 

3from . import * 

4 

5def select( 

6 optionList=[], 

7 valueList=False, 

8 multiple=False, 

9 span=2, 

10 htmlId=False, 

11 htmlClass=False, 

12 inlineHelpText=False, 

13 blockHelpText=False, 

14 required=False, 

15 disabled=False, 

16 popover=False, 

17 extraAttributeTupleList=False, 

18 defaultOption=False): 

19 """ 

20 *Generate a select - TBS style* 

21 

22 **Key Arguments** 

23 

24 - ``optionList`` -- the list of options 

25 - ``multiple`` -- display all the options at once? 

26 - ``span`` -- column span 

27 - ``htmlId`` -- the html id of the element 

28 - ``inlineHelpText`` -- inline and block level support for help text that appears around form controls 

29 - ``blockHelpText`` -- a longer block of help text that breaks onto a new line and may extend beyond one line 

30 - ``required`` -- required attribute if the field is not optional 

31 - ``disabled`` -- add the disabled attribute on an input to prevent user input 

32 - ``popover`` -- add helper text to the select 

33 - ``defaultOption`` -- option to select as default 

34  

35 

36 **Return** 

37 

38 - ``select`` -- the select 

39  

40 """ 

41 if not htmlId: 

42 htmlId = "" 

43 

44 if not htmlClass: 

45 htmlClass = "" 

46 

47 extraAttributes = "" 

48 if extraAttributeTupleList: 

49 for attributeTuple in extraAttributeTupleList: 

50 attr = attributeTuple[0] 

51 val = attributeTuple[1] 

52 if isinstance(val, ("".__class__, u"".__class__)) : 

53 val = '"%(val)s"' % locals() 

54 extraAttributes = """%(extraAttributes)s %(attr)s=%(val)s """ % locals( 

55 ) 

56 

57 if not valueList: 

58 valueList = optionList 

59 

60 if multiple is True: 

61 multiple = """multiple="multiple" """ 

62 else: 

63 multiple = "" 

64 

65 if span: 

66 span = "span%(span)s" % locals() 

67 else: 

68 span = "" 

69 

70 if popover is False: 

71 popover = "" 

72 

73 if inlineHelpText: 

74 inlineHelpText = """<span class="help-inline">%(inlineHelpText)s</span>""" % locals( 

75 ) 

76 else: 

77 inlineHelpText = "" 

78 

79 if blockHelpText: 

80 blockHelpText = """<span class="help-block">%(blockHelpText)s</span>""" % locals( 

81 ) 

82 else: 

83 blockHelpText = "" 

84 

85 options = "" 

86 for o, v in zip(optionList, valueList): 

87 if defaultOption and defaultOption == o: 

88 options = """%(options)s <option value="%(v)s" selected="selected">%(o)s</option>""" % locals() 

89 else: 

90 options = """%(options)s <option value="%(v)s">%(o)s</option>""" % locals() 

91 

92 if required: 

93 required = """required""" 

94 else: 

95 required = "" 

96 

97 if disabled: 

98 disabled = """disabled""" 

99 disabledId = "disabledId" 

100 else: 

101 disabled = "" 

102 disabledId = "" 

103 

104 select = """ 

105 <select %(multiple)s name="%(htmlId)s" class="%(span)s %(htmlClass)s" %(popover)s id="%(disabledId)s%(htmlId)s" %(required)s %(disabled)s %(extraAttributes)s> 

106 %(options)s 

107 </select>%(inlineHelpText)s%(blockHelpText)s 

108 """ % locals() 

109 

110 return select