tianzhuqiao / form

Form: form builder in Kotlin for Android
Apache License 2.0
15 stars 6 forks source link

FormItemTextAreaFloatingHint does not show "*" when requyired is true. #4

Closed Robin-AF closed 2 years ago

Robin-AF commented 2 years ago

Hi,

As far as I can tell when you have FormItemTextAreaFloatingHint and set .required(true) it does not show the * on the item like it does on the other items.

tianzhuqiao commented 2 years ago

Yeah, the * is appended to the item title; but usually FormItemTextAreaFloatingHint doesn't have a title. If you want to show the * in its hint, you cay try something like

    +FormItemTextAreaFloatingHint().hint("Multi-line text with floating hint here ...")
          .tag("notes").onSetup { item, viewHolder ->
                    val styledString = SpannableString(item.hint + "*")
                    styledString.setSpan(
                            ForegroundColorSpan(Color.RED),
                            styledString.length - 1,
                            styledString.length,
                            0
                        )
                    (viewHolder as? FormBaseTextViewHolder)?.let {
                            it.hintView?.hint = styledString
                    }
                }
Robin-AF commented 2 years ago

Thanks @tianzhuqiao thats a wondeful solution, I wonder if it might be nice to add to FormItemTextAreaFloatingHint by default seeing as this specific use case not have the title. What are your thoughts?

For now at least it's solved with this temporary solution.