question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. ItΒ collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Form (control | emitValue: true | false ): disable control should show in form.value

See original GitHub issue

πŸš€ feature request

Relevant Package

This feature request is for @angular/forms

Description

I would like see disable control value in onSubmit when we do (this.myForm.value). There are some situation where we want to disable control with default value. Right now i am preserving that default value in another variable.

Describe the solution you’d like

It is good to have one more optional param to just disable control but you will see value in this.myForm.value.

this.myForm.get('name').disable({onlySelf: true, emitEvent: false, emitValue: true});

third optional param emitValue?: true | false

Describe alternatives you’ve considered

Above one

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:7
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
indraraj26commented, May 3, 2020

That’s what getRawValue use for.

Retrieves all values regardless of disabled status. The value property is the best way to get the value of the group, because it excludes disabled controls in the FormGroup.

So whenever we work with form regardless of state we should use getRawValue instead of myForm.value as it serves the same purpose. I have worked with number of forms in my admin panel (even on other projects) i never had any situation where i want to exclude disabled controls.

Btw It would be great if angular team can implement optional third param as i mentioned above with that we do not have to take care anything one method for every situation.

1reaction
dylhunncommented, Jul 29, 2021

Basically, this issue is about the default behavior of a form when submitted: disabled controls are excluded. If you need to get disabled controls, you can use getRawValue. Without lots of community interest, it doesn’t seem worth the API complexity or bundle size cost to add this feature.

Note also: we are considering adding a readonly state to form controls which would be submitted; this might be a workaround if implemented.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to disable form control but keep value - Stack Overflow
Assuming you have a disabled property in your component. You have to retun null not false to enable the input. Share.
Read more >
Disabling Form Controls When Working With Reactive Forms ...
Instantiate a new FormControl with the disabled property set to true. FormControl({value: '', disabled: true}) . Calling control.disable() or control.enable() .
Read more >
FormControl - Angular
Default is false. emitEvent : When true or not supplied (the default), both the statusChanges and valueChanges observables emit events with the latest...
Read more >
A thorough exploration of Angular Forms - InDepth.Dev
valueAccessor) _throwError(dir, 'No value accessor for form control with'); /* . ... markAsDirty(); // `{emitModelToViewChange: false}` will make sure thatΒ ...
Read more >
Angular β€” Disable a Form while Preserving Form Control State
The disabled attribute doesn't work on a form tag as this is not in the html specifications. <form disabled> <input type=”text” name=”firstName” ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found