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


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="Redbaritone" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/Redbaritone/120/38745_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  Redbaritone
                    <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>So, just to be clear, you’re saying it’s not a bug that validate_email_changed() is only executed in applications where the email should be unique?</p>
<p>In my head, these validate_[attribute] methods are simply validating that the value conforms to specific characteristics, like these:</p>
<ul>
<li>It’s required (or not)</li>
<li>It has a certain minimum (and maximum?) length</li>
<li>It conforms to a certain pattern</li>
<li>It’s unique (based on the application)</li>
<li>It’s one of a list of possible values</li>
</ul>
<p>In my head (and based on my 34 years of programming experience), the fact that a value <em>has</em> to change from some other value in order to be valid, makes no sense. That’s not at all like the things listed above. To me, this check <em>doesn’t</em> belong <em>inside</em> the validation routine, it belongs alongside it. This way, I can reuse the validate_email() method in some other form, where a person’s email <em>might</em> change, but won’t be flagged if it’s not changed. But that’s just <em>me</em>. What do I know? Apparently, I need more training in this new form of logic.</p>
<p>Someone tell me why this wouldn’t work. I’m not in a position to test it myself.</p>
<pre>  def email_changeset(user, attrs, opts \\ []) do
    user
    |&gt; cast(attrs, [:email])
    |&gt; validate_email(opts)
    |&gt; validate_email_changed()
  end
</pre> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="370214" 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/an-email-shouldnt-have-to-change-to-be-valid/71834/12">Post #11</a>
	                </div>
	            </div>
              <div id="likers-container-370214" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="370214"
                     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="370216" data-post-id="370216">
  <section>
    <div class="post-wrap">


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<aside class="quote no-group" data-username="Redbaritone" data-post="12" data-topic="71834">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/redbaritone/48/38745_2.png" class="avatar"> Redbaritone:</div>
<blockquote>
<p>To me, this check <em>doesn’t</em> belong <em>inside</em> the validation routine, it belongs alongside it. This way, I can reuse the validate_email() method in some other form, where a person’s email <em>might</em> change, but won’t be flagged if it’s not changed.</p>
</blockquote>
</aside>
<p>I think by having a special purpose form that’s just for a user to change their email, which uses a special purpose changeset function that’s only used when someone is changing their email, makes for a simpler system design. If instead you have multiple forms where a user <em>might</em> change their email address then in all of those places you need to check <em>if</em> they are trying to change it <em>and</em> afterwards check if the side effects need to be run, makes for a complicated design.</p>
<p>It is your codebase so if you want the more complicated setup then that’s totally reasonable, but I also think it’s totally reasonable for the starting place that the generator provides is the more straightforward architecture</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="370216" 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/an-email-shouldnt-have-to-change-to-be-valid/71834/13">Post #12</a>
	                </div>
	            </div>
              <div id="likers-container-370216" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="370216"
                     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="370218" data-post-id="370218">
  <section>
    <div class="post-wrap">


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<aside class="quote no-group" data-username="Redbaritone" data-post="12" data-topic="71834">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/redbaritone/48/38745_2.png" class="avatar"> Redbaritone:</div>
<blockquote>
<p>So, just to be clear, you’re saying it’s not a bug that validate_email_changed() is only executed in applications where the email should be unique?</p>
</blockquote>
</aside>
<p>You are misunderstanding the generated code. This is what the docs right on top of <code>email_changeset</code> says as of the latest RC:</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">  @doc """
  A user changeset for registering or changing the email.

  It requires the email to change otherwise an error is added.

  ## Options

    * `:validate_unique` - Set to false if you don't want to validate the
      uniqueness of the email, useful when displaying live validations.
      Defaults to `true`.
  """
</code></pre>
<p>The changeset function you’re complaining about serves only 2 use cases that are generated along with it: user registration and users updating their own email in the settings.</p>
<aside class="quote no-group" data-username="Redbaritone" data-post="12" data-topic="71834">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/redbaritone/48/38745_2.png" class="avatar"> Redbaritone:</div>
<blockquote>
<p>In my head (and based on my 34 years of programming experience), the fact that a value <em>has</em> to change from some other value in order to be valid, makes no sense.</p>
</blockquote>
</aside>
<p>During registration, the email will go from nothing to something. On the settings page, the update email form submit event handler makes sure the email being submitted is different from the current email. This is why I say it’s not a bug.</p>
<aside class="quote no-group" data-username="Redbaritone" data-post="1" data-topic="71834">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/redbaritone/48/38745_2.png" class="avatar"> Redbaritone:</div>
<blockquote>
<p>In my situation, I’m creating a user system where only an administrator can add users.</p>
</blockquote>
</aside>
<p><img src="https://forum.elixirforum.com/images/emoji/apple/backhand_index_pointing_down.png?v=15" title=":backhand_index_pointing_down:" class="emoji only-emoji" alt=":backhand_index_pointing_down:" loading="lazy" width="20" height="20"></p>
<aside class="quote group-Phoenix-Core-Team" data-username="steffend" data-post="4" data-topic="71834">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/steffend/48/20548_2.png" class="avatar"> steffend:</div>
<blockquote>
<p>Indeed, those are the only use cases we had in mind for that changeset. For any other cases where you want to change other fields of a user, a separate changeset is the way to go! That’s also why there are separate changesets for confirmation and password change. For an admin interface, you definitely want a custom changeset <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>
</blockquote>
</aside> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="370218" 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/an-email-shouldnt-have-to-change-to-be-valid/71834/14">Post #13</a>
	                </div>
	            </div>
              <div id="likers-container-370218" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="370218"
                     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>