Making next field disabled until previous is selsected - angular6

ho to make input data field disabled in angular 6 until previous input data field is selected. Like I have one source field and one destination input field. So i want to make Destination field to be disabled until the Source is selected.

If I consider your source and destination input fields as Start Date and End Date input fields with type="date", then you can create the destionation field i.e. End Date field as readonly as shown below:
<input type="date" name="end_date" id="end_date" class="form-control" placeholder="* End Date" #endDate="ngModel" [(ngModel)]="end_date" required readonly>
And add a change function on your Source field i.e. Start Date field as shown below:
<input type="date" name="start_date" id="start_date" class="form-control" [min]="today" placeholder="* Start Date" [(ngModel)]="start_date == null ? '' :start_date" #startDate="ngModel" (change)="onDateChange($event)" required>
Now on your Component.ts file, create the same function (i.e. onDateChange($event)) to remove the readonly property from End Date field, which will execute whenever a change-event occur on Start Date field.
onDateChange(event) {
$("#end_date").prop('readonly', false);
}

Related

How edit input field with type = " "datetime-local"?

I need edit existing data in form. When I load data in form from model to input field with type="datetime-local" - its empty. If i write new value to it and send then evetything is fine.
So, for example, for input field with type "time" in html:
<form action="#" th:action="#{/schendule}" th:object="${jobDetailDTO}" method="post">
...
<div class="form-group">
<label class="checkbox-inline">
<input type="checkbox" data-toggle="toggle" id="everyDay" > Every day timer:
</label>
<input type="time" class="form-control" th:field="*{localTime}" disabled>
</div>
and I send data to spring controller
#PostMapping(value = "/schendule", consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
public String schenduleFtp(#Valid JobDetailDTO jobDetailDTO) throws SchedulerException {...
When I want to edit input i add model:
modelAndView.addObject("jobDetailDTO", jobDetailDTO);
Everything fine with field "time", but with type = dateTime-local, i have empty value in input tag whan trying to edit, how to bind LocalDateTime value from model to view ? In style like tinput time
tag?

Change output format of Date field in HTML form

We have a HTML form and I have pasted the code for our Date of Birth field below. When the user enters the date, it requests it in dd/mm/yyyy format. However, once they click off the field, it changes to yyyy/mm/dd. As a result, our CRM is not accepting it because of the format. Is there a way to keep it as dd/mm/yyyy?
<label><span class="dateInput dateOnlyInput"> <input id="00N0Y00000RWiNa" name="00N0Y00000RWiNa" size="100" placeholder="Date of Birth" class="textbox-n" type="text" onfocus="(this.type='date')" onblur="(this.type='text')" id="date" required="true" data-cip-id="00N0Y00000RWiNa"></span></label>
Thanks
James
first it would be good to make sure you have only one "id" attribute on the input field.
Here is an example that might help you.
Here I removed the first id to get rid of the error in jsfiddle.net
function formatDate() {
// select element
const date = document.querySelector('#date');
// pick up date
let currentValue = date.valueAsNumber;
// change type
date.type = "text";
// update value with prev set value from date picker
date.value = new Date(currentValue).toLocaleDateString('en-GB');
}
<label>
<span class="dateInput dateOnlyInput">
<input name="00N0Y00000RWiNa"
size="100"
placeholder="Date of Birth"
class="textbox-n"
type="text"
onfocus="(this.type='date')"
onblur="formatDate()"
required="true"
data-cip-id="00N0Y00000RWiNa"
id="date">
</span>
</label>

Validation failed due to manually inserted value

Value of filename is being manually inserted using this
<input type="file" ngf-select ng-model="file" name="file" id="file" onchange="document.getElementById('fileName').value = this.value.split('\\').pop().split('/').pop()" required>
Filename is being injected into fileName field using the file a user chooses. Validation fails as it treats that field as still being empty until I at least insert one more character. What can I do to fix that?
This is the validation part
<p ng-show="fileNameForm.fileNameInput.$error.required && fileNameForm.fileNameInput.$touched" class="help-block">File name is required.</p>
And the actual text field
<input name="fileNameInput" class="form-control" type="text" id="fileName" ng-model="document.fileName" ng-maxlength="255" required>
on change will not be evaluated if the model is changed programmatically and not by a change to the input value
you can use $scope.$watch to detect changes on ng-model
$scope.$watch('document.fileName', function(newValue, oldValue) {
//if(newValue not valid)
// display validation error
});

Compare date in date picker with current date

<div class="input-group" ng-init="d.expiredAt = toDate(d.expiredAt);">
<input type="text" class="form-control" uib-datepicker-popup="dd/MMM/yyyy"
is-open="popup1.opened" ng-required="false"
close-text="Close" ng-model="d.expiredAt" ng-readonly="!editing"/>
I want to compare this date with current date and highlight this field with red if it is < than current date.
I guess that the purpose of your feature is to notify / prevent user from selecting a date before today ?
If it's the case, the bootstrap-ui component you're using provides the feature :
minDate (Default: null) - Defines the minimum available date.
Requires a Javascript Date object.
If you declare the today's date in your controller :
$scope.now = new Date();
You can use it like this in your HTML :
<input type="text" min-date="now" class="form-control" uib-datepicker-popup="dd/MMM/yyyy"
is-open="popup1.opened" ng-required="false"
close-text="Close" ng-model="d.expiredAt" ng-readonly="!editing"/>
It will disable the selection of passed dates.

input field edit not updating ng-model for date picker?

I have created a date picker in Angular
<div class="datepicker-wrapper">
<label for="license_expiry_date">Start Date (YYYY-MM-DD)</label>
<input type="text" class="form-control" [ngModel]="fromDate | date: 'yyyy-MM-dd'" placeholder="Enter start date" (focus)="onPurchaseDateFocus('from')" name="start_date">
<div [hidden]="!isFromDatepickerVisible" class="datepicker-container">
<datepicker [(ngModel)]="fromDate" name="fromdatepicker" (selectionDone)="onDateSelectionDone('from')">
</datepicker>
</div>
</div>
I can select a date by using date picker which will update the ng-model, the input tag above the date picker is editable. but when I edit the date from the input field instead of date picker instead of selecting by date picker, ng-model is not getting updated.
Why is the value not updated when I edit the input field?
Not sure what's going wrong but my first guess is the one-way data binding on the form control.
[ngModel]="fromDate | date: 'yyyy-MM-dd'"
try to change it to
[(ngModel)]="fromDate | date: 'yyyy-MM-dd'"
More on two-way data binding
https://angular.io/docs/ts/latest/guide/template-syntax.html#!#two-way