Permalink
Browse files

Fixed Issue #1384 - provide a way to override input field's type attr…

…ibute
  • Loading branch information...
1 parent cbd65ce commit cbada718b9d402f56de56bbd7a526e4cf741ce28 @jczuchnowski jczuchnowski committed with fmpwizard Jan 6, 2013
@@ -121,6 +121,11 @@ trait BaseField extends FieldIdentifier with util.BaseField {
*/
def notOptionalErrorMessage : String = "Value required"
+ /**
+ * Form field's type.
+ * Defaults to 'text', but you may want to change it to other HTML5 values.
+ */
+ def formInputType = "text"
def tabIndex: Int = 1
@@ -50,7 +50,7 @@ trait DateTimeTypedField extends TypedField[Calendar] {
private def elem =
S.fmapFunc(SFuncHolder(this.setFromAny(_))){funcName =>
- <input type="text"
+ <input type={formInputType}
name={funcName}
value={valueBox.map(s => toInternetDate(s.getTime)) openOr ""}
tabindex={tabIndex toString}/>
@@ -41,7 +41,7 @@ trait NumericTypedField[MyType] extends TypedField[MyType] {
}
private def elem = S.fmapFunc((s: List[String]) => setFromAny(s)) {
- funcName => <input type="text" name={funcName} value={valueBox.map(_.toString) openOr ""} tabindex={tabIndex toString}/>
+ funcName => <input type={formInputType} name={funcName} value={valueBox.map(_.toString) openOr ""} tabindex={tabIndex toString}/>
}
/**
@@ -89,8 +89,10 @@ trait PasswordTypedField extends TypedField[String] {
override def notOptionalErrorMessage = S.?("password.must.be.set")
+ override def formInputType = "password"
+
private def elem = S.fmapFunc(SFuncHolder(this.setFromAny(_))){
- funcName => <input type="password"
+ funcName => <input type={formInputType}
name={funcName}
value={valueBox openOr ""}
tabindex={tabIndex toString}/>}
@@ -48,7 +48,7 @@ trait StringTypedField extends TypedField[String] with StringValidators {
private def elem = S.fmapFunc(SFuncHolder(this.setFromAny(_))) {
funcName =>
- <input type="text" maxlength={maxLength.toString}
+ <input type={formInputType} maxlength={maxLength.toString}
name={funcName}
value={valueBox openOr ""}
tabindex={tabIndex toString}/>
@@ -469,6 +469,18 @@ object FieldSpec extends Specification {
Full(<input name=".*" type="text" tabindex="1" value={num.toString} id="mandatoryIntField_id"></input>)
)
}
+
+ "IntField with custom HTML5 type" should {
+ val rec = CustomTypeIntFieldRecord.createRecord
+ val num = 123
+ passConversionTests(
+ num,
+ rec.customIntField,
+ JsRaw(num.toString),
+ JInt(num),
+ Full(<input name=".*" type="number" tabindex="1" value={num.toString} id="customIntField_id"></input>)
+ )
+ }
"LocaleField" should {
val rec = FieldTypeTestRecord.createRecord
@@ -260,3 +260,15 @@ class CustomFormatDateTimeRecord private () extends Record[CustomFormatDateTimeR
}
object CustomFormatDateTimeRecord extends CustomFormatDateTimeRecord with MetaRecord[CustomFormatDateTimeRecord]
+
+class CustomTypeIntFieldRecord private () extends Record[CustomTypeIntFieldRecord] {
+
+ def meta = CustomTypeIntFieldRecord
+
+ object customIntField extends IntField(this) {
+ override def formInputType = "number"
+ }
+
+}
+
+object CustomTypeIntFieldRecord extends CustomTypeIntFieldRecord with MetaRecord[CustomTypeIntFieldRecord]

0 comments on commit cbada71

Please sign in to comment.