-
Notifications
You must be signed in to change notification settings - Fork 4.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
p-dropdown [group]=true not set default value #5080
Comments
Yeap, I have a similar issue with my project when applying the group option to p-dropdown. It's easy to find. I appreciate your product and hope so this issue will be resolved soon. Thank you.
|
I'm having a similar issue with my project using form groups. The group dropdown doesn't update the text on the dropdown unless it is specifically changed within the dropdown. Other non-group dropdowns on the page work just fine. I tried switching to ngModel and had the same issue. I'm on 5.2.0. I've tried multiple workarounds including changing my value objects to strings (same result) and sorting the dropdown to have the initial value at the top and using "autoDisplayFirst" but this just displays the label for the group it is a part of. For a workaround I simply changed the placeholder to the display of the initial value if one exists as the value is already stored, just not displayed. In no ways optimal, but this works for now. Hope this is fixed soon, thanks for the great library! |
I'm having the same problem. This fix works for my use case: #5171 |
Same problem here... |
From what I can see the problem lies in the recursive call in the findOption(val: any, opts: any[], inGroup?: boolean): SelectItem {
--> if(this.group && !inGroup) {
let opt: SelectItem;
if(opts && opts.length) {
for(let optgroup of opts) {
--> opt = this.findOption(val, optgroup.items, true);
if(opt) {
break;
}
}
}
return opt;
}
else {
let index: number = this.findOptionIndex(val, opts);
return (index != -1) ? opts[index] : null;
}
} Best regards and thanks for a great lib. |
- In findOption(val: any, opts: any[], inGroup?: boolean):633, make sure that when the method have made the recursive call and is searchin among the items of a group, it does not treat the opts as a group.
Let's check this out for 5.2.1 then. |
I like the solution of @joelbinn and committed it, thank you guys. |
[x ] bug report => Search github for a similar issue or PR before submitting
[ ] feature request => Please check if request is not on the roadmap already https://github.com/primefaces/primeng/wiki/Roadmap
[ ] support request => Please do not submit support request here, instead see http://forum.primefaces.org/viewforum.php?f=35
I am performing a simple record of occurrence,
When I use the update option I load the form values from the database, like this: (ignore the rest of the missing code)
`this.ocorrenciaService.Load(id).subscribe(rs => {
Note that I have a variable called "loading" to indicate that the form has been fully loaded, and making the elements visible on the screen.
my formControll is initialized this way: (ignore the rest of the missing code)
this.form = fb.group({ 'id': [null], 'nome_paciente': [null, Validators.required], 'quarto': [null], 'data_ocorrencia': [null, Validators.required], 'medico_id': [null], 'procedimentos': [null], 'duracao': [null], 'entrada': [null], 'saida': [null], 'obs': [null], 'local': [null, Validators.required] });
Here is the layout of my dropdown: (ignore the rest of the missing code)
<div class="ui-g-12 ui-md-4 ui-lg-4"> {{form.controls['local'].value}} <span>Local (<span style="color: red">*</span>):</span> <p-dropdown *ngIf="!carregando" [options]="local" [style]="{'width':'100%'}" [formControlName]="local" placeholder="Selecione o local" [group]="true"></p-dropdown> <p-message *ngIf="isFieldValid('local')" severity="error" text="Campo obrigatório"></p-message> </div>
the problem is that using the group the dropdown does not get the value I preloaded, other dropdown works correctly and initializes the value correctly ...
Please tell us about your environment: Ubuntu
The text was updated successfully, but these errors were encountered: