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


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="silverdr" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/silverdr/120/23771_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  silverdr
                    <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">
								<aside class="quote no-group" data-username="Eiji" data-post="11" data-topic="65337">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/eiji/48/36743_2.png" class="avatar"> Eiji:</div>
<blockquote>
<p>So problems with nested form fields … where did I heard about it? <img src="https://forum.elixirforum.com/images/emoji/apple/smile.png?v=15" title=":smile:" class="emoji" alt=":smile:" loading="lazy" width="20" height="20"></p>
</blockquote>
</aside>
<p>Well… you were indirectly right! <img src="https://forum.elixirforum.com/images/emoji/apple/smiley.png?v=15" title=":smiley:" class="emoji" alt=":smiley:" loading="lazy" width="20" height="20"> Although not exactly a nested form’s problem but rather me adding an unwanted/unexpected collection member where it wasn’t meant to be. And masquerading this fact with some crashes <img src="https://forum.elixirforum.com/images/emoji/apple/tired_face.png?v=15" title=":tired_face:" class="emoji" alt=":tired_face:" loading="lazy" width="20" height="20"></p>
<aside class="quote no-group" data-username="Eiji" data-post="11" data-topic="65337">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/eiji/48/36743_2.png" class="avatar"> Eiji:</div>
<blockquote>
<p>If we again talk about <code>Decimal</code> value then you have almost the answer. Why almost? Because it does not accept nil …</p>
</blockquote>
</aside>
<p>I use <code>Decimal</code> functions in many places. It’s not about this. It was a side-thread caused by the temporarily hard to explain errors I encountered.</p>
<p>It is more about “how to handle such cases”. I could come up with:</p>
<ul>
<li>building a separate “read” model and transforming (normalising) data on reading from DB</li>
<li>doing the normalising in the end on the inputs themselves</li>
</ul>
<p>The first feels like an overkill for such relatively small problem to solve, while the latter feels a bit “hacky”, like hammering the transformed values into places against the framework’s will <img src="https://forum.elixirforum.com/images/emoji/apple/wink.png?v=15" title=":wink:" class="emoji" alt=":wink:" loading="lazy" width="20" height="20"></p>
<p>All that while doubting that my case is a very rare, isolated one and wondering if there is maybe already something built-in or a de facto standard Elixir/Ecto/Phoenix way of dealing with this kind of problems. Something I am simply not yet aware of.</p>
<aside class="quote no-group" data-username="Eiji" data-post="11" data-topic="65337">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/eiji/48/36743_2.png" class="avatar"> Eiji:</div>
<blockquote>
<p>That’s said still I recommend to go with a default value like <code>Decimal.new("0")</code> and use <code>input_value</code></p>
</blockquote>
</aside>
<p>I currently use <code>input_value</code> but having any default there doesn’t make much sense in the case at hand so I handle nil gracefully instead.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="336538" 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/preprocessing-values-for-inputs-in-a-phoenix-liveview-form/65337/12">Post #11</a>
	                </div>
	            </div>
              <div id="likers-container-336538" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="336538"
                     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="336541" data-post-id="336541">
  <section>
    <div class="post-wrap">


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<aside class="quote no-group" data-username="silverdr" data-post="12" data-topic="65337">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/silverdr/48/23771_2.png" class="avatar"> silverdr:</div>
<blockquote>
<p>It is more about “how to handle such cases”.</p>
</blockquote>
</aside>
<p>I wound focus on thinking in different direction … If it was not for that case then why <code>Decimal.normalise/1</code> has been added? Look that you can write a custom <code>Ecto.Type</code> that would do 1:1 of the <code>Decimal</code> stuff, but when it’s about to read a value from database you do again the same thing + normalisation. Whatever you choose is rather up to you. Such specific use cases rather don’t have a good practices guides.</p>
<p>I would rather look at your own code and decide what’s the best way comparing to overall style of your app. For example you may already have 1 or 2 custom <code>Ecto.Type</code>, so introducing another one would be relatively to your code style absolutely normal.</p>
<p>I also haven’t tried it, but there are other <code>PostgreSQL</code>-related solutions like selecting a column and cast it to real or converting a whole column to real type while working on <code>Decimal</code> at <code>Elixir</code> app side. As said I haven’t tested it, so I have no idea about performance, preserving precision and so on …</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="336541" 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/preprocessing-values-for-inputs-in-a-phoenix-liveview-form/65337/13">Post #12</a>
	                </div>
	            </div>
              <div id="likers-container-336541" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="336541"
                     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>