primeng icon indicating copy to clipboard operation
primeng copied to clipboard

AutoComplete input does not reflect model changes

Open ChrisA9 opened this issue 9 years ago • 15 comments

I'm submitting a ... (check one with "x")

[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

Plunkr Case (Bug Reports) http://plnkr.co/edit/r7DnQw?p=info

Current behavior Text does not clear from autocomplete box

Expected behavior Text should clear from autocomplete box

Please tell us about your environment: OS : WIndows 7

  • Angular version: 4.0.3

  • PrimeNG version: 4.0.1

  • Browser: Chrome 58.0.3029.110 (64-bit),

ChrisA9 avatar May 25 '17 13:05 ChrisA9

https://github.com/primefaces/primeng/issues/2778

sudheerj avatar May 27 '17 11:05 sudheerj

I've installed 4.0.2 but this bug is still there. I'm changing a variable that has a two way binding to a model but the change doesn't reflect the text box value.

ohadinho avatar Jun 02 '17 06:06 ohadinho

The issue occurs after selecting a value from the dropdown and trying to change it on OnSelect event handler

ohadinho avatar Jun 02 '17 13:06 ohadinho

@ohadinho I can't replicate the issue. The value is reflected after button clear using both single and multiple features.

sudheerj avatar Jun 10 '17 03:06 sudheerj

Steps to replicate:

  1. Press the arrow to open the dropdown
  2. Choose a value
  3. Debug "OnSelect" method and change the ngModel variable value.

Expected Result: Value is the same as you defined after the change on OnSelect method.

Actual Result: The change in variable binded to ngModel didn't affect the input text.

On Jun 10, 2017 06:47, "Sudheer Jonna" [email protected] wrote:

@ohadinho https://github.com/ohadinho I can't replicate the issue. The value is reflected after button clear using both single and multiple features.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/primefaces/primeng/issues/2882#issuecomment-307539635, or mute the thread https://github.com/notifications/unsubscribe-auth/AEqculVUF5yHTKUZA8qszHrMSXbpYi1gks5sChHGgaJpZM4NmX7r .

ohadinho avatar Jun 10 '17 08:06 ohadinho

primeNg version: 4.1.0

<p-autoComplete placeholder="Start typing name to see suggestions" formControlName="customerRequest" [suggestions]="customerResults" (completeMethod)="searchCustomer('customer_name', $event.query)" minLength="3" field="accountName" (onSelect)="setCustomerRequest($event)">

Start type 'abc' Do not choose a value from the option Perform clear (Here setting customerRequest to null)

Result: customerRequest (model) set to null but the field is not cleared/reset.

Expected: Field should be reset to null.

If I select some value from the option and clear, field is reset to null. Please address this issue.

thirumalai-kc avatar Jul 14 '17 15:07 thirumalai-kc

Issue exists in 4.1.2 as well

macleanpinto avatar Aug 11 '17 03:08 macleanpinto

primeNg version: 4.1.3

I noticed that p-autoComplete expects the model to be type object in the template. If the value is a string, the resolveFieldData method returns undefined, which sets the input value to an empty string.

Changing this fixes it for me:

[value]=\"value ? (field ? objectUtils.resolveFieldData(value,field)||'': value) : null\"

To:

[value]=\"value ? objectUtils.resolveFieldData(value,field)||value : null\"

Alternatively adding this at the top of the resolveFieldData method works as well (and is probably the safer way to handle it):

if (typeof data === 'string') {
    return data;
}

iblank avatar Aug 16 '17 21:08 iblank

The problem still exists in version 4.1.3, why did you close the issue?

metacoding avatar Sep 01 '17 21:09 metacoding

@iblank alternate method works for me....please make this change

billfranklin avatar Sep 05 '17 21:09 billfranklin

When i cleared the suggestions input field. It worked for my case. But issue still exists.

omerbuyuksar avatar Sep 12 '17 08:09 omerbuyuksar

Still broken, wanting to clear the control when a selection is made... I null out the bound model and the suggestions list onSelect within a setTimeout even... when you click elsewhere on the screen, it does clear out

stusquared avatar Oct 09 '17 18:10 stusquared

Status of this fix?

billfranklin avatar Oct 20 '17 20:10 billfranklin

Found a possiblle workaround. Check out this comment

MatteoMeil avatar Aug 04 '19 17:08 MatteoMeil

Another approach :

Create a template variable suppose @ViewChild('station', { static: true }) stationDrpdown: ElementRef;

in autoComplete tag #station (onSelect)="onStationSelection($event)"

onStationSelection(station){ ....

this.stationDrpdown['inputFieldValue']=station.name; ... }

DipankarDDUT avatar Sep 05 '22 09:09 DipankarDDUT