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


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Hi <a class="mention" href="/u/cenotaph" rel="nofollow">@cenotaph</a> - did you manage to solve your problem. I’m struggling to get <code>datepickr</code> to work correctly with LiveView 0.17.</p>
<p>cheers</p>
<p>Dave</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="239093" 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/correct-strategy-for-using-datepicker-attached-to-an-input-field-with-liveview/37775/12">Post #11</a>
	                </div>
	            </div>
              <div id="likers-container-239093" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="239093"
                     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="239107" data-post-id="239107">
  <section>
    <div class="post-wrap">


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Nope, I gave up on it and used html5 date picker.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="239107" 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/correct-strategy-for-using-datepicker-attached-to-an-input-field-with-liveview/37775/13">Post #12</a>
	                </div>
	            </div>
              <div id="likers-container-239107" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="239107"
                     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="239149" data-post-id="239149">
  <section>
    <div class="post-wrap">


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Ah that’s a shame - I think I’ll probably do the same.</p>
<p>cheers</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="239149" 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/correct-strategy-for-using-datepicker-attached-to-an-input-field-with-liveview/37775/14">Post #13</a>
	                </div>
	            </div>
              <div id="likers-container-239149" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="239149"
                     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="250692" data-post-id="250692">
  <section>
    <div class="post-wrap">


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>My man do you know how much heartburn I suffered today trying to fix this god forsaken thing and your solution pulled me from the depths of hades out of the clutches of Mephistopheles himself?</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="250692" data-batch-url="/posts/batch_likers">
                        5
                      </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/correct-strategy-for-using-datepicker-attached-to-an-input-field-with-liveview/37775/15">Post #14</a>
	                </div>
	            </div>
              <div id="likers-container-250692" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="250692"
                     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 #14"></div>
  </section>
</div>
    <div class="postbit" id="299987" data-post-id="299987">
  <section>
    <div class="post-wrap">


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>This is how I’m using today:</p>
<p>Put this inside the <code>core_components.ex</code></p>
<pre data-code-wrap="elixir"><code class="lang-elixir">  attr :id, :string, required: true
  attr :field, Phoenix.HTML.FormField,
    doc: "a form field struct retrieved from the form, for example: @form[:occurred_at]"
  attr :label, :string, default: nil
  def datetime_picker(assigns) do
    ~H"""
    &lt;div id={@id} phx-update="ignore"&gt;
      &lt;.input field={@field} phx-hook="DateTimePicker" type="text" label={@label} /&gt;
    &lt;/div&gt;
    """
  end
</code></pre>
<p>Create a new Hook:</p>
<pre data-code-wrap="js"><code class="lang-js">import flatpickr from "flatpickr"

/**
 * @type {import("phoenix_live_view").ViewHook}
 */
export const DateTimePicker = {
  mounted() {
    flatpickr(this.el, {
      enableTime: true,
      altFormat: "d/m/Y H:i",
      dateFormat: "Z",
      minuteIncrement: 1,
      time_24hr: true,
      altInput: true,
      static: true,
      wrap: false, 
    })
  },
} 
</code></pre>
<p>If you are usign TailwindCSS, put this inside you <code>app.css</code></p>
<pre data-code-wrap="css"><code class="lang-css">/**
 * Flatpickr fix full width
 */
.flatpickr-wrapper {
  @apply relative w-full;
}
</code></pre>
<p>And use like that</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">&lt;.datetime_picker
  id="occurred-at"
  field={@form[:occurred_at]}
  label="Occurred at"
/&gt;
</code></pre>
<p>This will work fine with <code>:utc_datetime</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="299987" data-batch-url="/posts/batch_likers">
                        10
                      </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/correct-strategy-for-using-datepicker-attached-to-an-input-field-with-liveview/37775/16">Post #15</a>
	                </div>
	            </div>
              <div id="likers-container-299987" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="299987"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-solved cat-solved" title="Marked as solution"></div>
  </section>
</div>
    <div class="postbit" id="300219" data-post-id="300219">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="rio517" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/rio517/120/20653_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  rio517
                    <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>I wound up going with a very similar solution in a subsequent project, except in my case, I needed to communicate validation errors in my form. I wound up wrapping my <code>phx-update="ignore"</code> with a parent node <code>&lt;dix phx-feedback-for="target"</code> and add some custom CSS to help render validation errors.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="300219" 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/correct-strategy-for-using-datepicker-attached-to-an-input-field-with-liveview/37775/17">Post #16</a>
	                </div>
	            </div>
              <div id="likers-container-300219" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="300219"
                     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 #16"></div>
  </section>
</div>
    <div class="postbit" id="303585" data-post-id="303585">
  <section>
    <div class="post-wrap">


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Would you mind showing an example of your error handling on the datepicker field? I’m doing something similar and I’m sort of new the way Elixir handles forms.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="303585" 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/correct-strategy-for-using-datepicker-attached-to-an-input-field-with-liveview/37775/18">Post #17</a>
	                </div>
	            </div>
              <div id="likers-container-303585" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="303585"
                     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 #17"></div>
  </section>
</div>
    <div class="postbit" id="351102" data-post-id="351102">
  <section>
    <div class="post-wrap">


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>I’m having issues integrating flatpickr using LiveView 1.0. The <a href="https://hexdocs.pm/phoenix_live_view/Phoenix.Component.html#used_input?/1" rel="noopener nofollow ugc">new way of keeping track of unused inputs</a> doesn’t seem to play nice with how flatpickr is initialized (at least not with the configuration permutations I’ve tried).</p>
<p>The params sent to the LV event handler (using <code>phx-change</code>) don’t contain the <code>_unused_xxx</code> parameter for the date input even if it’s not being touched. This makes the date input immediately seem used. In cases where the date input is validated as required for example, this makes the input show up with its error markup and validation error, even though another input is being edited.</p>
<p>Did anyone notice the same? I’ve tried the wrap <a href="https://flatpickr.js.org/options/" rel="noopener nofollow ugc">option</a> of flatpickr, but also the method of placing the altInput inside <code>phx-ignore</code> element. Without any luck. My hypothesis is that flatpickr “touches” the original input, which confuses the LiveView js runtime that keeps track of the used/unused inputs. But I’m unaware of the internals of this process.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="351102" 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/correct-strategy-for-using-datepicker-attached-to-an-input-field-with-liveview/37775/19">Post #18</a>
	                </div>
	            </div>
              <div id="likers-container-351102" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="351102"
                     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 #18"></div>
  </section>
</div>
    <div class="postbit" id="353025" data-post-id="353025">
  <section>
    <div class="post-wrap">


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p><a class="mention" href="/u/linusdm" rel="nofollow">@linusdm</a> did you figure this out? i’m in the same boat. I have it working without altInput but when altInput: true then the date picker doesn’t pop up</p>
<p>Edit: actually <a class="mention" href="/u/rodolfosilva" rel="nofollow">@RodolfoSilva</a> ’s solution works!</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="353025" 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/correct-strategy-for-using-datepicker-attached-to-an-input-field-with-liveview/37775/20">Post #19</a>
	                </div>
	            </div>
              <div id="likers-container-353025" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="353025"
                     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 #19"></div>
  </section>
</div>
    <div class="postbit" id="373977" data-post-id="373977">
  <section>
    <div class="post-wrap">


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Hi folks, here is my latest contribution to this component: Flatpickr with support for an unused feature from Phoenix.</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">
  attr :id, :string, required: true

  attr :field, Phoenix.HTML.FormField,
    doc: "a form field struct retrieved from the form, for example: @form[:email]"

  attr :label, :string, default: nil
  attr :class, :string, default: nil

  def datetime_picker(%{field: %Phoenix.HTML.FormField{} = field} = assigns) do
    errors = if Phoenix.Component.used_input?(field), do: field.errors, else: []
    assigns = assign(assigns, :errors, Enum.map(errors, &amp;translate_error(&amp;1)))

    ~H"""
    &lt;div id={@id} class={["fieldset mb-2", not Enum.empty?(@errors) &amp;&amp; "with-error"]}&gt;
      &lt;div&gt;
        &lt;label :if={@label} for={@field.id} class="label mb-1"&gt;{@label}&lt;/label&gt;
        &lt;div id={"#{@field.id}-picker"} class="relative" phx-hook=".Flatpickr" phx-update="ignore"&gt;
          &lt;input
            type="datetime-local"
            name={@field.name}
            id={@field.id}
            placeholder="dd/mm/yyyy hh:mm"
            value={normalize_iso_datetime(@field.value)}
            class={[@class || "input w-full", @errors != [] &amp;&amp; "input-error"]}
          /&gt;
        &lt;/div&gt;
        &lt;p :for={msg &lt;- @errors} class="text-error mt-1.5 flex items-center gap-2 text-sm"&gt;
          &lt;.icon name="hero-exclamation-circle" class="size-5" /&gt;
          {msg}
        &lt;/p&gt;
      &lt;/div&gt;
    &lt;/div&gt;
    &lt;script :type={Phoenix.LiveView.ColocatedHook} name=".Flatpickr"&gt;
      import flatpickr from "flatpickr";

      /**
      * @type {import("phoenix_live_view").ViewHook &amp; { picker: flatpickr.Instance }}
      */
      export default {
        mounted() {
          const input = this.el.querySelector("input")
          const originalType = input.getAttribute("type")
          this.picker = flatpickr(input, {
            enableTime: true,
            altFormat: "d/m/Y H:i",
            dateFormat: "Z",
            minuteIncrement: 1,
            time_24hr: true,
            altInput: true,
            static: true,
          })
          input.setAttribute("type", originalType);
          input.setAttribute("style", "display: none;");
        },
        destroyed() {
          this.picker.destroy()
          this.picker = null
        },
      }
    &lt;/script&gt;
    """
  end
</code></pre>
<p>This assumes that you are using Flatpickr with npm and the latest Phoenix/LiveView version.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="373977" data-batch-url="/posts/batch_likers">
                        2
                      </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/correct-strategy-for-using-datepicker-attached-to-an-input-field-with-liveview/37775/21">Post #20</a>
	                </div>
	            </div>
              <div id="likers-container-373977" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="373977"
                     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 #20"></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/37775/load_more?page=3">Load more posts (1 remaining)</a>
</div></template></turbo-stream>