<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Tone Phone</title>
    <description>The latest articles on DEV Community by Tone Phone (@goangu).</description>
    <link>https://dev.to/goangu</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F2939328%2F4ffd2c3a-392b-430f-86d9-ce5ac232a39b.png</url>
      <title>DEV Community: Tone Phone</title>
      <link>https://dev.to/goangu</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/goangu"/>
    <language>en</language>
    <item>
      <title>Mutually Exclusive Checkbox Selection with Reactive Forms</title>
      <dc:creator>Tone Phone</dc:creator>
      <pubDate>Mon, 17 Mar 2025 15:57:54 +0000</pubDate>
      <link>https://dev.to/goangu/mutually-exclusive-checkbox-selection-with-reactive-forms-4l0c</link>
      <guid>https://dev.to/goangu/mutually-exclusive-checkbox-selection-with-reactive-forms-4l0c</guid>
      <description>&lt;p&gt;I need some assistance with handling checkbox selection using angular. I have 4 checkboxes, ALL, FirstName, LastName, MiddleName. When the page loads ALL should be the only one selected. If I click any of the other boxes ALL should be deselected. Likewise if I click ALL again the other checkboxes should be deselected. Currently ALL is selected when the page loads. I then can click the other boxes.  However I can't click ALL unless I manually uncheck the other boxes. Any assistance you can provide will be greatly appreciated.  This is my first post so please excuse the formatting :).  &lt;/p&gt;

&lt;p&gt;— parent html&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; &amp;lt;form [formGroup]="reportListFG"&amp;gt;
     &amp;lt;app-form-type-filter 
                  [formGroup] ="reportListFG.get('filterGroup')"
                  (formTypeFilterChanged)="onFormTypeSelectionChange($event)"
                  (clear)="clearReceipt($event)" 
                  #formFilter&amp;gt;
     &amp;lt;/app-form-type-filter&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;—parent ts&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    this.reportListFG = this.fb.group(
    {
      Address: [[]],
      PhoneNumber: [[]],
      filterGroup: this.fb.group({
      ALL: [true],
      FirstName: [false],
      LastName: [false],
      MiddleName: [false],
      }),
      )

   //Listen to form changes and handle the logic for "All" and other 
   checkboxes
   this.reportListFG.get('filterGroup').valueChanges.subscribe(values =&amp;gt; 
{
  this.handleCheckboxSelection(values);
});

}

  handleCheckboxSelection(values: any) {
  const allSelected = values.ALL; 

  console.log('Inside handleCheckbox');

  // If "All" is selected and another box is checked, uncheck "All"
  if (allSelected &amp;amp;&amp;amp; (values.FirstName || values.LastName || 
    values.MiddleName)) {
    this.reportListFG.get('filterGroup')?.patchValue(
      {
        ALL: false
      },
      { emitEvent: false } // Prevent infinite loop
    );
  }

  // If "All" is selected, ensure other checkboxes remain unchecked
  else if (allSelected) {
    console.log(allSelected, '********');
    this.reportListFG.get('filterGroup')?.patchValue(
      {
        FirstName: false,
        LastName: false,
        MiddleName: false
      },
      { emitEvent: false } // Prevent infinite loop
    );
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

</description>
      <category>webdev</category>
      <category>programming</category>
      <category>angular</category>
      <category>javascript</category>
    </item>
  </channel>
</rss>
