Skip to content

Commit

Permalink
Better managing of null values in input control
Browse files Browse the repository at this point in the history
do not display "null"
do not forget to fill if nothing
  • Loading branch information
e-marchand committed Mar 19, 2024
1 parent 3c528ca commit e5b2058
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ abstract class BaseInputLessViewHolder(itemView: View, format: String) : BaseVie
}

override fun fill(value: Any) {
input.setText(formatToDisplay(value.toString()))
val string = if (value == JSONObject.NULL) "" else value.toString()
input.setText(formatToDisplay(string))
}

override fun getInputType(format: String): Int {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@ abstract class BaseTextViewHolder(itemView: View, private val format: String) :
}

override fun fill(value: Any) {
input.setText(formattedValue(value.toString()))
val string = if (value == JSONObject.NULL) "" else value.toString()
input.setText(formattedValue(string))
}

abstract fun onTextChanged(s: CharSequence)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ abstract class BaseViewHolder(itemView: View, format: String) : RecyclerView.Vie
itemJsonObject.getSafeString("defaultField")?.let { defaultField ->
ReflectionUtils.getInstanceProperty(entity, defaultField)?.let { value ->
valueCallback(value)
}
}
}
} ?: valueCallback(JSONObject.NULL)
} ?: valueCallback(JSONObject.NULL)
} ?: valueCallback(JSONObject.NULL)
}

fun isMandatory() = itemJsonObject.getSafeArray("rules")?.getStringList()?.contains("mandatory") ?: false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@ class DateViewHolder(
FormatterUtils.applyFormat(dateFormat, input)

override fun fill(value: Any) {
updatePickerDate(value.toString())
val string = if (value == JSONObject.NULL) "" else value.toString()
updatePickerDate(string)
super.fill(value)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ abstract class CustomViewViewHolder(
}

override fun fill(value: Any) {
if (value.toString().isNotEmpty()) {
val string = if (value == JSONObject.NULL) "" else value.toString()
if (string.isNotEmpty()) {
currentEditEntityValue = value
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,8 @@ class MenuViewHolder(
}

override fun fill(value: Any) {
if (value.toString().isNotEmpty()) {
val string = if (value == JSONObject.NULL) "" else value.toString()
if (string.isNotEmpty()) {
currentEditEntityValue = value
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,8 @@ class PopoverViewHolder(

override fun fill(value: Any) {
super.fill(value)
if (value.toString().isNotEmpty()) {
val string = if (value == JSONObject.NULL) "" else value.toString()
if (string.isNotEmpty()) {
currentEditEntityValue = value
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ class PushViewHolder(

override fun fill(value: Any) {
super.fill(value)
if (value.toString().isNotEmpty()) {
val string = if (value == JSONObject.NULL) "" else value.toString()
if (string.isNotEmpty()) {
currentEditEntityValue = value
}
}
Expand Down

0 comments on commit e5b2058

Please sign in to comment.