Skip to content

Commit e41c47a

Browse files
committed
* fixed problem with default ordering of form fields
1 parent b5cf0e9 commit e41c47a

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@ flexibility of the form design.
1616
Currently it is available as a sonatype snapshot, add this to your build.sbt:
1717

1818
```
19-
libraryDependencies += "com.github.torstenrudolf.scalajs-react-form-binder" %%% "core" % "0.0.14-SNAPSHOT"
19+
libraryDependencies += "com.github.torstenrudolf.scalajs-react-form-binder" %%% "core" % "0.0.15-SNAPSHOT"
2020
```
2121

2222
If you want to use the materialui form-field descriptors, you'll need this as well:
2323
```
24-
libraryDependencies += "com.github.torstenrudolf.scalajs-react-form-binder" %%% "extras" % "0.0.14-SNAPSHOT"
24+
libraryDependencies += "com.github.torstenrudolf.scalajs-react-form-binder" %%% "extras" % "0.0.15-SNAPSHOT"
2525
```
2626

2727

build.sbt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ def commonSettings: Project => Project =
33
_.enablePlugins(ScalaJSPlugin)
44
.settings(
55
organization := "com.github.torstenrudolf.scalajs-react-form-binder",
6-
version := "0.0.14-SNAPSHOT",
6+
version := "0.0.15-SNAPSHOT",
77
homepage := Some(url("https://github.com/torstenrudolf/scalajs-react-form-binder")),
88
licenses += ("MIT", url("https://opensource.org/licenses/MIT")),
99
scalaVersion := "2.11.8",

core/src/main/scala/torstenrudolf/scalajs/react/formbinder/Macros.scala

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,15 @@ object Macros {
118118
$defaultFormValue.map((dmv: $dataModelTypeSymbol)=> Map[String, Any](..${dataModelFields.map(fn => (fn.asTerm.name.toString, q"dmv.${fn.asTerm.name}"))})).getOrElse(${getDefaultValuesFromCompanionObject(c)(dataModelCompanion)})
119119
""")
120120

121-
val formFieldDescriptors = formLayout.info.members.sorted
121+
val preSortedFFDs = formLayout.info.members.sorted
122+
val formFieldDescriptors = formLayout.info.members
123+
.sorted // sorts in order of declaration, but inherited members appear later
124+
.sortBy(ffd => {
125+
//resort by order of fields in DataModel, but keep decls of read-only-fields where they were declared
126+
val i = targetFieldNames.indexOf(ffd.name.toString)
127+
if (i != -1) i
128+
else preSortedFFDs.indexOf(ffd) - 0.5 // keep it where it was
129+
})
122130
.map(_.asTerm)
123131
.filter(_.isAccessor)
124132
.filter(_.asMethod.returnType.<:<(typeOf[FormFieldDescriptor[_]]))

0 commit comments

Comments
 (0)