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


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="kevinschweikert" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/kevinschweikert/120/26866_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  kevinschweikert
                    <span class="op-star" title="Thread Starter">
                      <img alt="OP" class="op-star-icon" src="/assets/thread-icons/thread-icon-thread-starter-df91e872.png" />
                    </span>
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Uuuh nice! That’s even cleaner than to manipulate the query params. Thanks!</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="332705" 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/need-help-implementing-a-select-all-checkbox-with-form-data/64495/12">Post #11</a>
	                </div>
	            </div>
              <div id="likers-container-332705" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="332705"
                     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 #11"></div>
  </section>
</div>
    <div class="postbit" id="332706" data-post-id="332706">
  <section>
    <div class="post-wrap">


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Yes. Imo directly manipulating params is a sign of bad abstraction. It means your code doesn’t want to deal with the fact that indeed not all changes are provided by params.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="332706" 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/need-help-implementing-a-select-all-checkbox-with-form-data/64495/13">Post #12</a>
	                </div>
	            </div>
              <div id="likers-container-332706" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="332706"
                     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 #12"></div>
  </section>
</div>
    <div class="postbit" id="332759" data-post-id="332759">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="kevinschweikert" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/kevinschweikert/120/26866_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  kevinschweikert
                    <span class="op-star" title="Thread Starter">
                      <img alt="OP" class="op-star-icon" src="/assets/thread-icons/thread-icon-thread-starter-df91e872.png" />
                    </span>
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>For anybody finding this thread and needing a solution for the preselection:</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">def mount(_params, _session, socket) do
    categories = [%Category{id: 0, name: "Category 1", preselected: true}, %Category{id: 1, name: "Category 2", preselected: false}]

    preselected = Enum.filter(categories, &amp; &amp;1.preselected) |&gt; Enum.map(&amp; &amp;1.id)
    categories_form = parse_filter(%{all: false, selected: []}, %{all: false, selected: preselected})
    categories_filter = apply_filter(categories_form)
    categories_options = Enum.map(categories, &amp;{&amp;1.name, &amp;1.id})

    {:ok,
     assign(socket,
       categories: categories,
       filtered_categories: filter_categories(categories, categories_filter),
       filter: categories_filter,
       options: categories_options,
       preselected: preselected
     )
     |&gt; assign_form(categories_form)}
  end

  def handle_params(params, _, socket) do
    form = 
      parse_filter(socket.assigns.filter, params) 
      |&gt; maybe_add_preselected(socket.assigns.preselected)

    filter = apply_filter(form)

    {:noreply,
     socket
     |&gt; assign(
       filter: filter,
       filtered_categories: filter_categories(socket.assigns.categories, filter),
       preselected: []
     )
     |&gt; assign_form(form)}
  end

 @spec maybe_add_preselected(Ecto.Changeset.t(), [integer()]) :: Ecto.Changeset.t()
  defp maybe_add_preselected(changeset, preselected) when preselected == [], do: changeset

  defp maybe_add_preselected(changeset, preselected) do
    case Ecto.Changeset.fetch_change(changeset, :selected) do
      {:ok, []} -&gt; Ecto.Changeset.change(changeset, selected: preselected)
      _ -&gt; changeset
    end
  end
</code></pre> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="332759" 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/need-help-implementing-a-select-all-checkbox-with-form-data/64495/14">Post #13</a>
	                </div>
	            </div>
              <div id="likers-container-332759" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="332759"
                     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 #13"></div>
  </section>
</div>
    <div class="postbit" id="332819" data-post-id="332819">
  <section>
    <div class="post-wrap">


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Saw this blog post from FullStackPhoenix that is also related. <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>
<aside class="onebox allowlistedgeneric" data-onebox-src="https://fullstackphoenix.com/tutorials/add-bulk-actions-in-phoenix-liveview">
  <header class="source">

      <a href="https://fullstackphoenix.com/tutorials/add-bulk-actions-in-phoenix-liveview" target="_blank" rel="noopener nofollow ugc" title="09:41PM - 09 November 2020">FullstackPhoenix – 9 Nov 20</a>
  </header>

  <article class="onebox-body">
    <div class="aspect-image" style="--aspect-ratio:600/315;"><img src="https://res.cloudinary.com/dwvh1fhcg/image/upload/w_600,c_scale/v1643955757/xhhaqakseb6yyrcfbjwm.jpg" class="thumbnail" alt="" width="600" height="315"></div>

<h3><a href="https://fullstackphoenix.com/tutorials/add-bulk-actions-in-phoenix-liveview" target="_blank" rel="noopener nofollow ugc">Add bulk actions in Phoenix LiveView</a></h3>

  <p>In this tutorial, I have a list of customers. One common feature for a table of records is to perform some sort of bulk actions. As an example in this tutorial, I want to be able to toggle all records</p>


  </article>

  <div class="onebox-metadata">
    
    
  </div>

  <div style="clear: both"></div>
</aside>
 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="332819" 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/need-help-implementing-a-select-all-checkbox-with-form-data/64495/15">Post #14</a>
	                </div>
	            </div>
              <div id="likers-container-332819" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="332819"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-last-post cat-last-post" title="Last post!"></div>
  </section>
</div>
</template></turbo-stream><turbo-stream action="replace" target="load-more-container"><template><div id="load-more-container" class="load-more-container">
    <span class="all-loaded">— All posts loaded —</span>
</div></template></turbo-stream>