<turbo-stream action="append" target="posts_list"><template>    <div class="postbit" id="173813" data-post-id="173813">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="sandeshsoni" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/sandeshsoni/120/14466_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  sandeshsoni
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Thanks, my purpose solved.</p>
<p>If anyone comes to this thread for same situation … select country, then state then city,<br>
here is how I solved.</p>
<p>I did not need to create a liveview-component.</p>
<p>In my <code>formcomponent.ex</code></p>
<pre data-code-wrap="elixir"><code class="lang-elixir">  def handle_event("validate", params, socket) do
    form_title = "landmark"
    landmark_params = params[form_title]
    [form_title, target] = params["_target"]
    target_value = landmark_params[target]

    result = case target do
               "city_id" -&gt; add_regions(socket, target_value)
               _ -&gt; validate_form(socket, landmark_params)
             end

    {:noreply, result}
  end

  defp add_regions(socket, city_code) do .... assign(socket, :cities, calculated)  end
  defp validate(.... , ...) do validation_logic end
.
.
.
</code></pre>
<p>Any better solution, welcome.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="173813" data-batch-url="/posts/batch_likers">
                        1
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/liveview-phx-change-attribute-does-not-emit-event-on-input-text/21280/22">Post #21</a>
	                </div>
	            </div>
              <div id="likers-container-173813" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="173813"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #21"></div>
  </section>
</div>
    <div class="postbit" id="173816" data-post-id="173816">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="tfwright" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/tfwright/120/20299_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  tfwright
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Personally I find using hooks a perfectly acceptable solution for this situation, in conjunction with using pushEvent to trigger Liveview handlers. Maybe I don’t have the same amount of distaste for writing JavaScript as others, but when it comes to dom event handlers JS seems to work fine, especially for edge cases like gigantic data heavy forms. It’s the rendering step where LV is indispensable. The phx-* handlers seem more like conveniences than critical features of a Liveview template.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="173816" data-batch-url="/posts/batch_likers">
                        1
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/liveview-phx-change-attribute-does-not-emit-event-on-input-text/21280/23">Post #22</a>
	                </div>
	            </div>
              <div id="likers-container-173816" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="173816"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #22"></div>
  </section>
</div>
    <div class="postbit" id="175586" data-post-id="175586">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="hourliert" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/hourliert/120/13674_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  hourliert
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Hi <img src="https://forum.elixirforum.com/images/emoji/apple/wave.png?v=15" title=":wave:" class="emoji" alt=":wave:" loading="lazy" width="20" height="20"></p>
<p>Reviving this post a little bit.<br>
I am currently building a form that contains one auto-complete input (but without using the HTML5 <code>&lt;datalist /&gt;</code> as I want to style the list).</p>
<p>I managed to build it and generate the list of autocompletions using <code>phx-change</code> binding on my form.</p>
<p>Now, I would like to extract this autocomplete input so I can re-use it in other forms.<br>
So far, I have created a livecomponent for it, and pass the form builder struct to this new component. I have also writen a hooks to push an event to the live component on <code>input</code> to refresh the suggestion list.</p>
<p>My issue is that while this work well, the <code>change</code> of the parent form also triggers. And there is a concurrent update of the DOM which leads to super janky experience (the form blinks).<br>
<strong>Is there a way to prevent the form to run <code>phx-change</code> , from the autocomplete component</strong> ? I tried to use <code>e.preventDefault()</code> and <code>e.stopPropagation()</code> in my hook but it didn’t work.</p>
<p>I know there is a way to pattern match on the target in the <code>handle_even("validate..")</code> for my form component, but this feels wrong to me. The parent should have to be aware of the input to “ignore” from a child component. This seems private to the autocomplte component.</p>
<p>Thanks in advance.</p>
<p><strong>EDIT</strong></p>
<p>I might have something quite elegant, using <a href="https://hexdocs.pm/phoenix_live_view/Phoenix.LiveComponent.html#module-live-component-blocks" rel="noopener nofollow ugc">Live components block</a>.</p>
<ul>
<li>The Form component (where the form <code>f</code> lives) now calls:</li>
</ul>
<pre data-code-wrap="elixir"><code class="lang-elixir">&lt;%= live_component @socket, AutocompleteComponent, id: :some_id %&gt;
  &lt;%= hidden_input f, :item_id, value: @selected_item.id %&gt;
&lt;% end %&gt;
</code></pre>
<ul>
<li>The AutocompleteComponent basically does:</li>
</ul>
<pre data-code-wrap="elixir"><code class="lang-elixir">&lt;%= if @selected_item do %&gt;
  &lt;%= @inner_content.(selected_item: @selected_item) %&gt;
&lt;% end %&gt;
&lt;% text_input :unused_form_id, :query, phx_keyup: "search_item" %&gt;

&lt;%= unless @selected_item do %&gt;
  &lt;%= for item &lt;- @results do %&gt;
    &lt;a phx-click="select_item" phx-value-id="&lt;%= item.id %&gt;" phx-target="&lt;%= @myself %&gt;"&gt;
      &lt;%= item.name %&gt;
    &lt;/a&gt;
  &lt;% end %&gt;
&lt;% end %&gt;
</code></pre>
<p>The logic of searching and selecting item is now self-contained into the <code>AutocompleteComponent</code>, exactly what I wanted.</p>
<p>Thanks for you time if you read this post <img src="https://forum.elixirforum.com/images/emoji/apple/slight_smile.png?v=15" title=":slight_smile:" class="emoji" alt=":slight_smile:" loading="lazy" width="20" height="20"></p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="175586" data-batch-url="/posts/batch_likers">
                        3
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/liveview-phx-change-attribute-does-not-emit-event-on-input-text/21280/24">Post #23</a>
	                </div>
	            </div>
              <div id="likers-container-175586" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="175586"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #23"></div>
  </section>
</div>
    <div class="postbit" id="189769" data-post-id="189769">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="thojanssens1" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/thojanssens1/120/17642_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  thojanssens1
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p><code>phx_change</code> being only allowed on the form element causes me a lot of frustrations when working with live view.</p>
<p>Case:</p>
<p>I have a nested form (<code>inputs_for</code>) listing a list of entities; you can add/edit/remove an entity.</p>
<p>I must attach <code>phx-change</code> to the form to support editing all text fields; otherwise, if for example I add or delete an entity from that nested form, the changeset will not include the entered text. Therefore, for every text entered, I update the changeset.</p>
<p>Problem:</p>
<p>I was listening a checkbox in the same form through <code>phx_click</code>, that when clicked some updates are done in the changeset. Changes seemed alright when logging but the view was not correct… after some research I noticed it conflicted somehow with that global <code>phx_change</code> listener. The changes done after the checkbox click in <code>phx_click</code> are immediately reset in the <code>phx_change</code> event. So there was no other choice then to move all the code handling that checkbox in <code>phx_change</code> (and imagine having an increasing amount of actions controlled by form inputs for which you have to change the changeset… the listener on form changes will get huge). I’m still busy on that now but I find the code became horribly complex.<br>
Problem with putting such code into <code>phx_change</code> is that it’s not trivial to know whether the checkbox changed its state. Have to take the changeset and compare with the form params, before creating the new changeset from the params; and this for every other such inputs.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="189769" data-batch-url="/posts/batch_likers">
                        4
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/liveview-phx-change-attribute-does-not-emit-event-on-input-text/21280/25">Post #24</a>
	                </div>
	            </div>
              <div id="likers-container-189769" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="189769"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #24"></div>
  </section>
</div>
    <div class="postbit" id="191439" data-post-id="191439">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="Clemens" src="/assets/icons/user-9f439610.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  Clemens
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>You can add phx-change behavior to individual inputs by using the <a href="https://www.w3schools.com/tags/att_form.asp" rel="noopener nofollow ugc">form attribute</a></p>
<p>Example:</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">&lt;form phx-change="individual_event" id="individual_form"&gt;
&lt;/form&gt;

&lt;form phx-change="save" id="product_form"&gt;
  &lt;input type="text" name="product[name]"&gt;
  ...
  &lt;input type="text" id="individual_input" form="individual_form"&gt;
&lt;/form&gt;
</code></pre>
<p>We added a separate form (outside the main form) for the individual input. When you now change the value of the <span class="hashtag-raw">#individual_input</span>, the  “individual_event” will be emitted.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="191439" data-batch-url="/posts/batch_likers">
                        1
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/liveview-phx-change-attribute-does-not-emit-event-on-input-text/21280/26">Post #25</a>
	                </div>
	            </div>
              <div id="likers-container-191439" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="191439"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #25"></div>
  </section>
</div>
    <div class="postbit" id="191443" data-post-id="191443">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="thojanssens1" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/thojanssens1/120/17642_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  thojanssens1
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>That’s some form of hack, which shows that something is wrong when you need to resort to such things.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="191443" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/liveview-phx-change-attribute-does-not-emit-event-on-input-text/21280/27">Post #26</a>
	                </div>
	            </div>
              <div id="likers-container-191443" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="191443"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #26"></div>
  </section>
</div>
    <div class="postbit" id="193127" data-post-id="193127">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="Athunnea" src="/assets/icons/user-9f439610.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  Athunnea
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>But when you submit the <code>product_form</code> you won’t get the data from <code>individual_input</code> with it, because technically they belong to the <code>individual_form</code></p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="193127" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/liveview-phx-change-attribute-does-not-emit-event-on-input-text/21280/28">Post #27</a>
	                </div>
	            </div>
              <div id="likers-container-193127" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="193127"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #27"></div>
  </section>
</div>
    <div class="postbit" id="193130" data-post-id="193130">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="Athunnea" src="/assets/icons/user-9f439610.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  Athunnea
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>It’s unfortunate that <code>phx-change</code> is not supported on the input level.</p>
<p>I need to add an autocomplete field to the existing form in eex template. I expected it to be as easy as inserting <code>render_live</code> to render a LV component inside a form. Now I know that it won’t work without attaching <code>phx-change</code> to the form, which cannot be done without rewriting the whole action from controller to LV. So I’m kind of stuck right now, exploring other options.</p>
<p>I played with  <code>phx-change</code> on a form and I cannot say I understand it. On a complex form with many fields (data, filters, checkboxes, etc) it generates a lot of noise, and you have to parse params to understand what’s happening. Wrapping each element in its own form makes you wonder why then do you need a form element at all, if it becomes just a stub for a hook. Maybe I just need some enlightenment</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="193130" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/liveview-phx-change-attribute-does-not-emit-event-on-input-text/21280/29">Post #28</a>
	                </div>
	            </div>
              <div id="likers-container-193130" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="193130"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #28"></div>
  </section>
</div>
    <div class="postbit" id="193158" data-post-id="193158">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="sfusato" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/sfusato/120/11569_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  sfusato
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<aside class="quote no-group" data-username="Athunnea" data-post="29" data-topic="21280">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/letter_avatar_proxy/v4/letter/a/8e7dd6/48.png" class="avatar"> Athunnea:</div>
<blockquote>
<p>Now I know that it won’t work without attaching <code>phx-change</code> to the form, which cannot be done without rewriting the whole action from controller to LV. So I’m kind of stuck right now, exploring other options.</p>
</blockquote>
</aside>
<p>There’s <code>phx-trigger-action</code> which allows your form to trigger a standard form submit to a controller and still use LV.</p>
<aside class="quote no-group" data-username="Athunnea" data-post="29" data-topic="21280">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/letter_avatar_proxy/v4/letter/a/8e7dd6/48.png" class="avatar"> Athunnea:</div>
<blockquote>
<p>On a complex form with many fields (data, filters, checkboxes, etc) it generates a lot of noise, and you have to parse params to understand what’s happening.</p>
</blockquote>
</aside>
<p>By parse do you mean pattern match? You can be as granular as you want and have a <code>handle_event</code> callback for each form’s field if that’s what you want. Or ignore some fields. Check the <code>_target</code> key in the event’s payload.</p>
<aside class="quote no-group" data-username="Athunnea" data-post="29" data-topic="21280">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/letter_avatar_proxy/v4/letter/a/8e7dd6/48.png" class="avatar"> Athunnea:</div>
<blockquote>
<p>It’s unfortunate that <code>phx-change</code> is not supported on the input level.</p>
</blockquote>
</aside>
<p>My point being you can already achieve a <code>phx-change</code> like effect at the input level.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="193158" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/liveview-phx-change-attribute-does-not-emit-event-on-input-text/21280/30">Post #29</a>
	                </div>
	            </div>
              <div id="likers-container-193158" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="193158"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #29"></div>
  </section>
</div>
    <div class="postbit" id="220032" data-post-id="220032">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="Maxim-Filimonov" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/Maxim-Filimonov/120/20878_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  Maxim-Filimonov
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Chiming in here with several use cases we have run into while developing our app.<br>
We use Surface heavily which pushed us a lot into using <code>live_component</code>. Which worked great… Until we realized that we cannot handle any input changes inside our <code>live_component</code> without adding a form. And as soon as we try to put <code>live_component</code> inside another form it all breaks as forms cannot be nested based on HTML5 specification.</p>
<p>We have many autocomplete and select fields and need to resort to writing lots of custom hooks with push events through alpine just to work around it.<br>
I do feel that it shows that the current implementation of <code>live_component</code> needs more work. Specifically, the <code>change</code> event based on <a href="https://dev.w3.org/html5/spec-LC/common-input-element-attributes.html#common-event-behaviors" rel="noopener nofollow ugc">HTML5 specification</a> is raised on the element, not on the form. It only bubbles to the form:</p>
<blockquote>
<p>When the user agent changes the element’s <a href="https://dev.w3.org/html5/spec-LC/association-of-controls-and-forms.html#concept-fe-value" rel="noopener nofollow ugc">value</a> on behalf of the user (e.g. as part of a form prefilling feature), the user agent must follow these steps:</p>
<ol>
<li>If the <code>input</code> event applies, <a href="https://dev.w3.org/html5/spec-LC/webappapis.html#queue-a-task" rel="noopener nofollow ugc">queue a task</a> to <a href="https://dev.w3.org/html5/spec-LC/webappapis.html#fire-a-simple-event" rel="noopener nofollow ugc">fire a simple event</a> that bubbles named <code>input</code> at the <code>input</code> element.</li>
<li>If the <code>change</code> event applies, <a href="https://dev.w3.org/html5/spec-LC/webappapis.html#queue-a-task" rel="noopener nofollow ugc">queue a task</a> to <a href="https://dev.w3.org/html5/spec-LC/webappapis.html#fire-a-simple-event" rel="noopener nofollow ugc">fire a simple event</a> that bubbles named <code>change</code> at the <code>input</code> element.</li>
</ol>
</blockquote>
<p>A simple use case that is trivial in React or even plain javascript seems quite problematic to make work with <code>live_component</code>.<br>
We have a <code>live_component</code> with pairs of select input and text input. When a certain select value is selected the input field should be hidden. Right now we hack it with this:</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">&lt;Select
              class="w=1/3 border bg-white rounded py-2 outline-none"
              options={space_type_options(index)}
              opts={
                "x-model": "selectedType",
                id: "subpremiseSelector2",
                "phx-hook": "Inputs.SubpremiseInputs#subpremiseInputs",
                "x-on:change": "subpremiseInputs.pushEventTo($el, 'type_changed', $el.value)"
              }
            /&gt;

    &lt;div data-show={@show} x-show="selectedType!=$el.dataset.show"&gt;
            &lt;Field name={:value}&gt;
              &lt;TextInput class="border bg-white rounded py-2 outline-none" opts={hook: "subpremiseInputs"} /&gt;
              &lt;ErrorTag /&gt;
            &lt;/Field&gt;
          &lt;/div&gt;

# the hook
let subpremiseInputs = {
  mounted() {
    window.subpremiseInputs = this;
  },
};

window.subpremiseInputs = subpremiseInputs;
export { subpremiseInputs };

</code></pre>
<p>Being able to just have <code>phx-change</code> on select and handle_event inside the <code>live_component</code> would remove the need for custom hook hacking and adding alpine magic where its not necessary needed.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="220032" data-batch-url="/posts/batch_likers">
                        6
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/liveview-phx-change-attribute-does-not-emit-event-on-input-text/21280/31">Post #30</a>
	                </div>
	            </div>
              <div id="likers-container-220032" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="220032"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-most-liked cat-most-liked" title="One of the top 3 liked posts in this thread!"></div>
  </section>
</div>
</template></turbo-stream><turbo-stream action="replace" target="load-more-container"><template><div id="load-more-container" class="load-more-container">
    <a class="load-more-button" data-turbo-stream="true" href="/topics/21280/load_more?page=4">Load more posts</a>
</div></template></turbo-stream>