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 range 

3from . import * 

4 

5def formInput( 

6 ttype="text", 

7 placeholder="", 

8 span=2, 

9 htmlId=False, 

10 searchBar=False, 

11 pull=False, 

12 prepend=False, 

13 append=False, 

14 button1=False, 

15 button2=False, 

16 prependDropdown=False, 

17 appendDropdown=False, 

18 inlineHelpText=False, 

19 blockHelpText=False, 

20 focusedInputText=False, 

21 rightText=False, 

22 required=False, 

23 disabled=False, 

24 defaultValue=False, 

25 hidden=False, 

26 divWrap=True): 

27 """ 

28 *Generate a form input - TBS style* 

29 

30 **Key Arguments** 

31 

32 - ``ttype`` -- [ text | password | datetime | datetime-local | date | month | time | week | number | float | email | url | search | tel | color ] 

33 - ``placeholder`` -- the placeholder text 

34 - ``span`` -- column span 

35 - ``htmlId`` -- html id 

36 - ``searchBar`` -- is this input a searchbar? 

37 - ``pull`` -- [ false | right | left ] align form 

38 - ``prepend`` -- prepend text to the input. 

39 - ``append`` -- append text to the input. 

40 - ``button1`` -- do you want a button associated with the input? 

41 - ``button2`` -- as above for a 2nd button 

42  

43 

44 - ``appendDropdown`` -- do you want a appended button-dropdown associated with the input? 

45 - ``prependDropdown`` -- do you want a prepended button-dropdown associated with the input? 

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

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

48 - ``focusedInputText`` -- make the input focused by providing some initial editable input text 

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

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

51 - ``defaultValue`` -- a default value to be passed to action script 

52 - ``hidden`` -- hide the CG from the user? 

53 - ``divWrap`` -- wrap in div 

54 

55 **Return** 

56 

57 - ``input`` -- the input 

58  

59 """ 

60 prependContent = False 

61 appendContent = False 

62 inputId = False 

63 searchClass = False 

64 prependClass = False 

65 appendClass = False 

66 

67 if hidden: 

68 hidden = u"""hidden""" 

69 else: 

70 hidden = u"" 

71 

72 falseList = [searchBar, span, prepend, prependContent, append, 

73 appendContent, inputId, pull, htmlId, appendClass, prependClass] 

74 

75 for i in range(len(falseList)): 

76 if not falseList[i]: 

77 falseList[i] = u"" 

78 

79 [searchBar, span, prepend, prependContent, append, appendContent, 

80 inputId, pull, htmlId, appendClass, prependClass] = falseList 

81 

82 if pull: 

83 pull = u"pull-%(pull)s" % locals() 

84 

85 if span: 

86 span = u"span%(span)s" % locals() 

87 

88 if searchBar: 

89 searchClass = u"search-query" 

90 else: 

91 searchClass = u"" 

92 

93 if prepend: 

94 prependClass = u"input-prepend" 

95 prependContent = u"""<span class="add-on">%(prepend)s</span>""" % locals( 

96 ) 

97 

98 if append: 

99 appendClass = u"input-append" 

100 appendContent = u"""<span class="add-on">%(append)s</span>""" % locals() 

101 

102 # if prepend: 

103 # if append: 

104 # inputId = "appendedPrependedInput " 

105 # else: 

106 # inputId = "prependedInput " 

107 # elif append: 

108 # inputId = "appendedInput " 

109 

110 if button1: 

111 appendClass = u"input-append" 

112 appendContent = button1 

113 # inputId = "appendedInputButton " 

114 

115 if button2: 

116 appendClass = u"input-append" 

117 appendContent = u"""%(appendContent)s %(button2)s""" % locals() 

118 # inputId = "appendedInputButtons " 

119 

120 if appendDropdown: 

121 appendClass = u"input-append" 

122 # inputId = "appendedDropdownButton " 

123 appendContent = u""" 

124 <div class="btn-group"> 

125 %(appendDropdown)s 

126 </div>""" % locals() 

127 

128 if prependDropdown: 

129 prependClass = u"input-prepend" 

130 # inputId = "prependedDropdownButton " 

131 prependContent = u""" 

132 <div class="btn-group"> 

133 %(prependDropdown)s 

134 </div>""" % locals() 

135 

136 step = u"" 

137 if ttype == "float": 

138 step = u""" step="any" """ 

139 ttype = u"number" 

140 

141 if prependDropdown and appendDropdown: 

142 pass 

143 # inputId = "appendedPrependedDropdownButton " 

144 

145 if inlineHelpText: 

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

147 ) 

148 else: 

149 inlineHelpText = u"" 

150 

151 if blockHelpText: 

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

153 ) 

154 else: 

155 blockHelpText = u"" 

156 

157 if not focusedInputText: 

158 focusedInputText = u"" 

159 focusId = u"" 

160 else: 

161 focusedInputText = u"""value="%(focusedInputText)s" """ % locals() 

162 focusId = u"focusedInput " 

163 

164 if required: 

165 required = u"""required""" 

166 else: 

167 required = u"" 

168 

169 if disabled: 

170 disabled = u"""disabled""" 

171 disabledId = u"" 

172 else: 

173 disabled = u"" 

174 disabledId = u"" 

175 

176 if defaultValue: 

177 if isinstance(defaultValue, ("".__class__, u"".__class__)) or isinstance(defaultValue, str): 

178 defaultValue = defaultValue.replace('"', "\"") 

179 defaultValue = u'"%(defaultValue)s"' % locals() 

180 

181 defaultValue = u"""value=%(defaultValue)s """ % locals() 

182 else: 

183 defaultValue = u"" 

184 

185 thisInput = u""" 

186 %(prependContent)s 

187 <input class="%(searchClass)s %(span)s" id="%(htmlId)s%(focusId)s%(disabledId)s" %(focusedInputText)s type="%(ttype)s" %(step)s placeholder="%(placeholder)s" %(required)s %(disabled)s name="%(htmlId)s" %(defaultValue)s> 

188 %(appendContent)s 

189 """ % locals() 

190 

191 if rightText is not False: 

192 thisInput = u"""<label class="inline">%(thisInput)s%(rightText)s </label>""" % locals( 

193 ) 

194 

195 if divWrap: 

196 formInput = u""" 

197 <div class="%(prependClass)s %(appendClass)s %(hidden)s %(pull)s"> 

198  

199 %(thisInput)s  

200  

201 </div>%(inlineHelpText)s%(blockHelpText)s 

202 """ % locals() 

203 else: 

204 formInput = thisInput 

205 

206 return formInput