I'm trying to set the color of a label in Angular 2 depending on its email-validation like this:
<input type="email" name="email" [(ngModel)]="email" email #currentEmail="ngModel" [ngClass]="currentEmail.invalid ? 'error' : 'none'">
It works as expected on my page, however in Visual Studio Code I get the following error message:
Error: ExpressionChangedAfterItHasBeenCheckedError: Expression has changed after it was checked. Previous value: 'error'. Current value: 'none'.
So my questions are:
Why does this message show up?
Whats the right approach to do this task?
Why does this message show up?
You can find a good explaination of why in this issue
This is not a bug, it's a feature of dev mode working as intended. Calling enableProdMode( ) - when bootstrapping the app prevents the exception from being thrown.
That said, it's being thrown for good reason: In short, after every round of change detection, dev mode immediately performs a second round to verify that no bindings have changed since the end of the first, as this would indicate that changes are being caused by change detection itself.
In your plunk, you have the binding [attr.spinner]=isLoading, and isLoading changes as a result of your call to this.load(), which occurs when ngAfterViewInit is fired, which happens as a part of the initial change detection turn. That in itself isn't problematic though - the problem is that this.load() changes a binding but does not trigger a new round of change detection, which means that this binding will not be updated until some future round of change detection.
Whats the right approach to do this task?
Simply replace [ngClass] with [class]. I don't know why, but when trying to reproduce your issue in a plunker, I found out that [class] does not trigger the error.
Edit : use ng-invalid class
You can also style your element based on the angular class ng-invalid.
See this plunker
Related
In svelte if I setup a <select> control like this:
<select bind:value={selected} on:change="{() => changeTheme()}">
the change event fires correctly and the value is bound but I get a warning in vscode:
(!) Plugin svelte: A11y: on:blur must be used instead of on:change, unless absolutely necessary and it causes no negative consequences for keyboard only or screen reader users.
If I change the binding to on:blur as described, the event only works if you click elsewhere in the page after you make your selection (causing the select control to lose focus). on:click kind of works, but is annoying.
on:change seems correct - how do I clear this warning?
All you need to do is put a comment above the line with your select element.
<!-- svelte-ignore a11y-no-onchange -->
You will need to reload the window to clear the error. https://svelte.dev/docs#Comments if you're ever curious how to disable a warning in VS code it tells you the name of it after the warning, whatever is in the parenthesis goes after svelte-ignore.
ion-toggle ionChange get called multiple times in ionic. I have tried using different techniques to solve it but I am not successful.
Code 1:
<ion-toggle
(ionChange)="changeData()"
color="success"
checked="{{data}}"
>
</ion-toggle>
Problem: When I used code 1 then ionChange get called multiple time and it does not show correct state first time.
Code 2:
<ion-toggle
(ionChange)="changeData()"
color="success"
[(ngModel)]="data"
>
</ion-toggle>
Problem: Code 2 causes infinite loop. It calls ionChange infinitly.
If anybody has faced similar issue and/or anybody knows how to tackle it then please let me know. Thanks
Infinite loop or multiple time calling of a method can be occurs if you are changing the the value of boolean in (ionChange)="changeData()" while you are already using [(ngModel)]="data" which is changing boolean value on toggling. So remove any code in your code which is changing data on ionChange.
I was facing similar problem when i was changing the value of boolean on ionChange while i was already using [(ngModel)].
So remove any code similar to code below in changeData() method:
// remove code which is changing state again
data = !data
I solved in the following way, remove the link from ngModel or checked with some variable. To go back to the previous state I map with the viewChild and control it from there.
Online test link
here
This question is regarding aem 6.3
I have an assignment that requires me to use a checkbox in the table. But I notice that when I do that, I am unable to create a new row through the workflow. May I know is there a workaround over it?
In my console logs, I am getting this error
TypeError: Cannot read property 'id' of undefined at child.handleAccessibility...
Am I suppose to create an id first? If so how do I do that?
Thanks
Norman
It appears to be that aem currently has a bug where the title of the checkbox cannot be hidden if not it will face the aforementioned error. So the solution is not hide the title but let it be blank.
This is more of an issue of that the id cannot be recognised, instead of unable to create a new row through the workflow, that resulted in the latter issue.
With the sap.m.DateTimePicker, it's possible for a user to either select a value from the drop-down list or enter it manually. I'm wondering if there's a way to add a mask to the manual input box that matches the valueFormat of the DateTimePicker.
I know there's a sap.m.MaskInput as well, so maybe there's a way to combine the two elements.
There is a new private module named sap.m.MaskEnabler which the sap.m.InputBase (i.e. DateTimePicker) is supposed to make use of.
(MaskEnabler) should be applied to the prototype of a sap.m.InputBase.
The mask feature is currently enabled only in sap.m.TimePicker (v1.54). According to this commit message, however, the same feature will arrive to the Date(Time)Picker as well:
This change prepares for refactoring of DatePicker and TimePicker so the
common code of both pickers can be moved to a new common control that
they may extend.
Therefore, if it's not urgent, and depending on your project, I'd not create a new custom control and then throw it away once the mask feature has arrived.
I'll update my answer when it's available.
Until then (and even afterwards), you can still guide the user to enter the data in the correct format via OData binding type sap.ui.model.odata.type.DateTime:
<DateTimePicker
value="{
path: 'myODataModel>myDateTime',
type: 'sap.ui.model.odata.type.DateTime',
constraints: {
isDateOnly: true,
displayFormat: 'Date'
}
}"
minDate="{...}"
maxDate="{...}"
/>
In contrast to formatter, type allows us to keep two-way data binding.
The entered value is automatically intercepted from updating the model data when...
It could not be parsed due to an invalid format (fires parseError)
It could be parsed but the constraints were violated (fires validationError)
If you enable handling UI messages
additionally, the framework will then take care of creating the appropriate
message for the user:
Example: https://stackoverflow.com/a/48482544
I think the only way to combine the two sap.m.DateTimePicker and sap.m.MaskInput is to develop your own control . Documentation : https://sapui5.hana.ondemand.com/#/topic/91f1703b6f4d1014b6dd926db0e91070.
Another way is to just use the Placeholder of the DateTimePicker Input field. This does not provide the same functionality as a MaskInput, but helps the user which valueFormat is expected in the input when entering it manually.
If you have a binding in your input box, you could set the type in the binding to eg. sap.ui.model.type.Date. This way you get some automatic formatting when field validation is triggered. There are other types available and you could inherit from sap.ui.model.SimpleType to code your own.
Recently, I started noticing odd behavior with one of my continuous forms. It contains text boxes in the header which can be used to filter the list. For some reason, whenever this form is requeried, for example when a record is edited or added in another form, this form reverts to its unfiltered state.
I stepped through the code and played around with some variables in the immediate window. The filter is still there, it just isn't being applied. Setting Me.FilterOn = True does nothing, as it is already true. A work around is easy, I can set Me.Filter = Me.Filter, but I would like to find out what is causing this behavior in the first place.
I have other contiunous forms that work completely fine; requerying them does not do anything to the filter. I'm assuming I changed some setting on the problematic form, but I have no idea what. I compared all the settings between the two forms in the property window and found nothing. Does anyone have any idea what is causing this behavior?
Well I figured out what was wrong. I realized the query that the form was based on was a pass-through query. As soon as I changed it to a normal access query, the problem went away.
Unfortunately I had it as a pass-through query for a reason. Mircosoft Access doesn't like my join. Sometimes it throws me a join not supported error, and other times it just gives me screwed up results... Looks like I'll have to rethink this query.