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

Remove phx-page-loading and phx-capture-click #1676

Open
josevalim opened this issue Oct 18, 2021 · 12 comments
Open

Remove phx-page-loading and phx-capture-click #1676

josevalim opened this issue Oct 18, 2021 · 12 comments
Assignees

Comments

@josevalim
Copy link
Member

No description provided.

@shortly-portly
Copy link

Hi @josevalim. May I ask why phx-capture-click is being removed? I've used phx-capture-click with a component on a modal to prevent the modal from receiving click events (and in my case submitting a form too early). What, if any, is the alternative to this. thanks.

@josevalim
Copy link
Member Author

There is phx-click-away or something similar.

@shortly-portly
Copy link

shortly-portly commented Jan 15, 2022

Thanks for the quick reply but I'm struggling to see how phx-click-away would replace phx-capture-click - so apologies if I'm missing something obvious.

As an example, I have a component which mimics a select dropdown. The below code is a skeleton example:

  def select(assigns) do
    ~H"""
      <div id="item">
        <div>Hello</div>
        <div>Hello</div>
        <div>Hello</div>
      </div>
      <button phx-capture-click={JS.toggle(to: "#item")}> 
        toggle!
      </button>
    """
  end

I can include this "select" component inside a form component that comes with Liveview 0.17.5. If I replace the phx-capture-click with a phx-click then the click event bubbles up and causes the form itself to submit - which isn't what I want. How would phx-click-away replace the functionality provided by phx-capture-click.

cheers

Dave

@josevalim
Copy link
Member Author

Wouldn’t phx-click be enough for this case?

@shortly-portly
Copy link

No because phx-click bubbles up to the form component which sees it as a submit and then submits the form. With phx-capture-click the click is captured and shows/hides the select as appropriate.

For another example, standard forms are normally shown in a modal - without the phx-capture-click the modal also receives the click event and closes.

@josevalim
Copy link
Member Author

I see. That’s something for Chris to consider then when going ahead with these deprecations! Thanks for clarifying!

@shortly-portly
Copy link

No problem. I've said it before but thanks for an awesome language and framework.

@chrismccord
Copy link
Member

<button> by default in an HTML form is type="submit". When you have a button in a form that you don't want to submit it, you need to specify <button type="button". In this case, the capture click was a band-aid around the missing attribute :)

@shortly-portly
Copy link

Ah so my example was incorrect. I'll have another go at implementing my dropdown using the JS style of commands. Thanks for the help (and the amazing framework of course).

@shortly-portly
Copy link

HI Chris - I reimplemented my dropdown with just JS style commands and it works perfectly.

@josevalim
Copy link
Member Author

I think those have been deprecated but the JavaScript code may still handle them.

@rhcarvalho
Copy link
Contributor

Is this something to consider removing for the 1.0.0 release if it is still in the code base?

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

No branches or pull requests

4 participants