-
Couldn't load subscription status.
- Fork 1
V2.0 #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
V2.0 #1
Changes from 1 commit
aefe699
2d65f7d
7d152f3
0c303ad
17b1688
5aad56f
56ee058
5cbf3b3
aeebeb7
37996cd
8f906f4
1de035b
96391ff
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -77,9 +77,10 @@ type alias CategoryButton = | |
|
|
||
| Controls should be rendered in accordance with these options. | ||
|
|
||
| - `label` - Label of the control, to be shown above the control. | ||
| - `id` - Unique identifier for the control, to be used as the "id" attribute. | ||
| - `required` - Whether the control should be marked as required, with an asterisk or similar. | ||
| Note that the control may or may not actually be required. | ||
| Note that the control may or may not _actually_ be required. | ||
| - `validation` - Validation state of the control, possibly containing an error value. | ||
| - `description` - Description of the control, to be shown below the control. | ||
| - `onFocus` - Used only to show field descriptions on focus. | ||
|
|
@@ -89,6 +90,7 @@ Controls should be rendered in accordance with these options. | |
| -} | ||
| type alias Options = | ||
| { label : Maybe String | ||
|
||
| , ariaLabel : String | ||
| , id : String | ||
| , disabled : Bool | ||
| , required : Bool | ||
|
|
@@ -167,6 +169,7 @@ type FieldFormat | |
| | Date | ||
| | Time | ||
| | DateTime | ||
| | Phone | ||
|
|
||
|
|
||
| {-| Text area control | ||
|
|
@@ -184,8 +187,7 @@ type alias TextArea = | |
| {-| Select control. | ||
| -} | ||
| type alias Select = | ||
| { value : String | ||
| , valueList : List { label : String, selected : Bool } | ||
| { valueList : List { label : String, selected : Bool } | ||
| , onChange : String -> Msg | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -145,74 +145,81 @@ controlWidget defaultOptions uiState wholeSchema control form = | |
| defOptions = | ||
| UI.applyDefaults defaultOptions control.options | ||
|
|
||
| disabled = | ||
| defOptions.readonly == True || uiState.disabled | ||
| elementId = | ||
| inputElementId form.formId control.scope | ||
|
|
||
| dispRequired = | ||
| isRequired wholeSchema control.scope && not defOptions.hideRequiredAsterisk | ||
| controlOptions subSchema = | ||
| let | ||
| disabled = | ||
| defOptions.readonly == True || uiState.disabled | ||
|
|
||
| validation = | ||
| if validateWidget control.scope form.validateWidgets then | ||
| case F.getErrorAt control.scope form.errors of | ||
| Just e -> | ||
| Invalid e | ||
| dispRequired = | ||
| isRequired wholeSchema control.scope && not defOptions.hideRequiredAsterisk | ||
|
|
||
| Nothing -> | ||
| Valid | ||
| validation = | ||
| if validateWidget control.scope form.validateWidgets then | ||
| case F.getErrorAt control.scope form.errors of | ||
| Just e -> | ||
| Invalid e | ||
|
|
||
| else | ||
| NotValidated | ||
| Nothing -> | ||
| Valid | ||
|
|
||
| showDescription subSchema = | ||
| if defOptions.showUnfocusedDescription || form.focus == Just control.scope then | ||
| subSchema.description | ||
| else | ||
| NotValidated | ||
|
|
||
| else | ||
| Nothing | ||
| label = | ||
| fieldLabel control.label subSchema control.scope | ||
|
|
||
| showDescription = | ||
| if defOptions.showUnfocusedDescription || form.focus == Just control.scope then | ||
| subSchema.description | ||
|
|
||
| else | ||
| Nothing | ||
| in | ||
| { id = elementId | ||
| , label = label.label | ||
| , ariaLabel = label.ariaLabel | ||
| , disabled = disabled | ||
| , validation = validation | ||
| , required = dispRequired | ||
| , description = showDescription | ||
| , onFocus = Focus control.scope | ||
| , trim = defOptions.trim | ||
| } | ||
|
|
||
| pointedValue = | ||
| Maybe.withDefault (FieldValue.String "") <| | ||
| FieldValue.pointedFieldValue control.scope form.value | ||
|
|
||
| elementId = | ||
| inputElementId form.formId control.scope | ||
|
|
||
| controlBody : SubSchema -> Maybe Widget | ||
| controlBody : SubSchema -> Maybe Control | ||
| controlBody subSchema = | ||
| Maybe.map | ||
| (WControl | ||
| { id = elementId | ||
| , label = fieldLabel control.label subSchema control.scope | ||
| , disabled = disabled | ||
| , validation = validation | ||
| , required = dispRequired | ||
| , description = showDescription subSchema | ||
| , onFocus = Focus control.scope | ||
| , trim = defOptions.trim | ||
| } | ||
| ) | ||
| <| | ||
| case subSchema.type_ of | ||
| SingleType IntegerType -> | ||
| Just <| textLikeControl IntField pointedValue control.scope elementId defOptions subSchema | ||
|
|
||
| SingleType NumberType -> | ||
| Just <| textLikeControl NumberField pointedValue control.scope elementId defOptions subSchema | ||
|
|
||
| SingleType StringType -> | ||
| Just <| textLikeControl (StringField <| formatFromSchema subSchema.format) pointedValue control.scope elementId defOptions subSchema | ||
|
|
||
| SingleType BooleanType -> | ||
| Just <| | ||
| CCheckbox | ||
| { value = FieldValue.asBool pointedValue | ||
| , onCheck = Input control.scope << FieldValue.Bool | ||
| } | ||
| case subSchema.type_ of | ||
| SingleType IntegerType -> | ||
| Just <| textLikeControl IntField pointedValue control.scope elementId defOptions subSchema | ||
|
|
||
| _ -> | ||
| Nothing | ||
| SingleType NumberType -> | ||
| Just <| textLikeControl NumberField pointedValue control.scope elementId defOptions subSchema | ||
|
|
||
| SingleType StringType -> | ||
| Just <| textLikeControl (StringField <| formatFromSchema subSchema.format) pointedValue control.scope elementId defOptions subSchema | ||
|
|
||
| SingleType BooleanType -> | ||
| Just <| | ||
| CCheckbox | ||
| { value = FieldValue.asBool pointedValue | ||
| , onCheck = Input control.scope << FieldValue.Bool | ||
| } | ||
|
|
||
| _ -> | ||
| Nothing | ||
|
|
||
| subSchemaWidget : SubSchema -> Maybe Widget | ||
| subSchemaWidget subSchema = | ||
| Maybe.map (WControl <| controlOptions subSchema) <| controlBody subSchema | ||
| in | ||
| Maybe.andThen controlBody <| UI.pointToSubSchema wholeSchema control.scope | ||
| Maybe.andThen subSchemaWidget <| UI.pointToSubSchema wholeSchema control.scope | ||
|
|
||
|
|
||
| textLikeControl : FieldType -> FieldValue -> Pointer -> String -> UI.DefOptions -> SubSchema -> Control | ||
|
|
@@ -237,8 +244,7 @@ textLikeControl fieldType fieldValue pointer elementId defOptions subSchema = | |
|
|
||
| else | ||
| CSelect | ||
| { value = FieldValue.asString fieldValue | ||
| , valueList = | ||
| { valueList = | ||
| Maybe.toList subSchema.enum | ||
| |> List.concat | ||
| |> List.map (Decode.decodeValue UI.decodeStringLike >> Result.withDefault "") | ||
|
|
@@ -352,26 +358,26 @@ isRequired wholeSchema pointer = | |
| isCheckboxRequired || isPropertyRequired | ||
|
|
||
|
|
||
| fieldLabel : Maybe UI.ControlLabel -> SubSchema -> Pointer -> Maybe String | ||
| fieldLabel : Maybe UI.ControlLabel -> SubSchema -> Pointer -> { label : Maybe String, ariaLabel : String } | ||
| fieldLabel label schema scope = | ||
| let | ||
| fallback = | ||
| schema.title | ||
| |> Maybe.orElse (List.last scope |> Maybe.map UI.fieldNameToTitle) | ||
| |> Maybe.withDefault "" | ||
| |> Maybe.withDefault "unreachable" | ||
|
||
| in | ||
| case label of | ||
| Just (UI.StringLabel s) -> | ||
| Just s | ||
| { label = Just s, ariaLabel = s } | ||
|
|
||
| Just (UI.BoolLabel False) -> | ||
| Nothing | ||
| { label = Nothing, ariaLabel = fallback } | ||
|
|
||
| Just (UI.BoolLabel True) -> | ||
| Just fallback | ||
| { label = Just fallback, ariaLabel = fallback } | ||
|
|
||
| Nothing -> | ||
| Just fallback | ||
| { label = Just fallback, ariaLabel = fallback } | ||
|
|
||
|
|
||
| inputElementId : String -> Pointer -> String | ||
|
|
@@ -410,6 +416,9 @@ formatFromSchema = | |
| "date-time" -> | ||
| DateTime | ||
|
|
||
| "phone" -> | ||
| Phone | ||
|
|
||
| _ -> | ||
| Text | ||
| ) | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.