Skip to content
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

input type not dynamic #283

Open
paolino opened this issue Jan 21, 2019 · 7 comments
Open

input type not dynamic #283

paolino opened this issue Jan 21, 2019 · 7 comments

Comments

@paolino
Copy link

paolino commented Jan 21, 2019

Trying to add the classic switch from visible to invisible password field. The dynamic attributes are not controlling the "type" attribute.

do
                    seeD :: DS Bool <- icon ["eye"] >>= foldDyn (const  not) False
                    let pwAttrD  = fmap ("name" =: "password" <> ) $ ffor seeD $ \case
                            True -> "type" =: "password"
                            False -> "type" =: "text"
                    (u,pw) <- elAttr "form" ("autocomplete" =: "on" <> "name" =: "login") $ do
                        u <- divClass "username" $ do
                            text "email"
                            textInput $ def
                                & set textInputConfig_inputType "email"
                                & set textInputConfig_attributes
                                    (constDyn $ "name" =: "username")
                        pw <- divClass "password" $ do
                            text "password"
                            textInput $ def
                                -- & set textInputConfig_inputType "password"
                                & set textInputConfig_attributes
                                    pwAttrD
                        return (u,pw)
@tomsmalley
Copy link
Member

You should use inputElement instead: textInput sets the type explicitly with the _inputType field, as you've seen. This overrides any dynamic "type" attribute. I believe we are going to be moving away from textInput and friends, but unfortunately the examples haven't caught up yet.

@tomsmalley tomsmalley added the bug label Jan 22, 2019
@paolino
Copy link
Author

paolino commented Jan 23, 2019

Thanks for pushing me to the source, so now I have my eye-featured password field.

Regarding TextInput obsolescence, I think a dedicated constant config field for the input type attribute was a good idea and the see / not see dynamic is indeed a special case for modern password fields.

Nevertheless, I cannot think of a valid application of the rewrite interpretation of the textInputConfig_inputType field.

So, if we don't come up with a counter example where rewriting the dynamic attribute is an expected / wanted feature, I would propose a breaking back compatibility change with a fallback interpretation of the inputType field, betting it will actually break no old code and give us the the chance to reuse TextInput for optionally observable password fields.

@dfordivam
Copy link
Member

@paolino actually the textInput is already in a "backward compatibility"/deprecation cycle. There is a bigger problem with this API that it cannot work with prerender/ static rendering.
So for all new code inputElement is the recommended API to use.

@luigy perhaps textInput should have a deprecated marking?

@ali-abrar
Copy link
Member

It seems to me that if you're changing the type of the input, you should probably wrap the whole thing in some kind of Workflow that knows how to handle the switching and convert the value of the input from the type expected by the initial input to the type expected by the switched input. What would happen, for example, if you switched from "text" to "checkbox"?

@dredozubov
Copy link

@paolino can you post the workaround for the problem? I agree the current implementation of textInput looks completely broken in regard of it bluntly overwriting the textInputConfig_inputType value.

@paolino
Copy link
Author

paolino commented Jun 27, 2019 via email

@dredozubov
Copy link

That's what I did as well, thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants