Skip to content

Form is marked dirty when dropdown is pre-populated #39

@adulfan

Description

@adulfan

I have a dropdown that get's pre-populated with default first value from the options, when the form is created it's empty all values are null but then inputs$ that I am using from ngx-sub-form on subscribe are populated with the dropdown values so the form becomes pristine:false and the form is marked as dirty, I am not clear how to fix it. Thank you


initControlWithOptions() {
    if (this.autoDisplayFirst && this.options && this.options.length > 0 && this.control) {
      const firstOptionValue = this.optionValue ? this.options[0][this.optionValue] : this.options[0];
      this.control.patchValue(firstOptionValue, { emitEvent: true });
    }
  }

Angular version: 17
 
For Tooling issues:
- Node version: v18.17.0  
- Platform:  Mac 

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions