ngx-bootstrap has a custom implementation for datepicker locales.
As my project is already using moment.js locales, i'm wondering is it possible to use moment.js locales with ngx-bootstrap datepicker?
yes, you can use both the follow way:
<div class="row">
<div class="col-xs-12">
<label>Date</label>
<input [(ngModel)]="distributionDate"
required tabindex="2"
class="form-control"
placeholder="please select a date"
bsDatepicker
[bsConfig]="{ dateInputFormat: 'MMMM D, YYYY', containerClass: 'theme-red' }"
(onHidden)="dateIsValid('distributionDate')"/>
</div>
</div>
[bsConfig]= that use format defined by moment.
(onHidden)= event that is executed when you out of field
you can define in some service to consume or only in your component.
dateIsValid(fieldName) {
if (!isNullOrUndefined(this[fieldName])) {
if (moment(this.formatDate(this[fieldName]), 'MMMM D, YYYY', true).isValid()) {
this[fieldName] = this.formatDate(this[fieldName]);
this.errors[fieldName] = false;
return true;
} else {
this.errors[fieldName] = true;
return false;
}
}
}
Related
How do I change the format of text input in datepicker dynamically with vue and datepicker component. When annual checkbox is click the format is 'dd MMMM' and when the checkbox is uncheck the format is 'dd MMMM yyyy'.
I am using Vue3 with #vuepic/vue-datepicker package.
Currently I already set the format as reactive value which in my understanding should rerender the component if the value change.
<template>
<div>
<Datepicker v-model="date" autoApply :format="format" />
<label>
<input type="checkbox" v-model="isAnnual" :value="true"> Annual
</label>
</div>
</template>
<script setup>
import { ref, watch } from 'vue';
import Datepicker from '#vuepic/vue-datepicker';
import '#vuepic/vue-datepicker/dist/main.css';
const date = ref(new Date);
const format = ref('dd MMMM yyyy');
const isAnnual = ref(false);
watch(isAnnual, (val) => {
if (val) {
format.value = "dd MMMM"
} else {
format.value = "dd MMMM yyyy"
}
})
</script>
Hate being this guy, but wouldn't it be easier to have a single format for annual and not annual?
But you can always ust the
JSON.syringify(Object)
and attempt to use moment to format.
You can maybe use ternary operator inside the format value like -
<Datepicker v-model="date" autoApply :format="isAnnual ? dd MMMM : dd MMMM yyyy" />
<div class="col-sm-8">
<i class="far fa-calendar-alt"></i>
<input
id="dtpFrom"
type="text"
placeholder="Datepicker"
placement="top"
class="form-control"
bsDatepicker
[bsConfig]="{dateInputFormat: 'DD MMM YYYY',containerClass: 'theme-blue'}"
[bsValue]="todayDate"
[minDate]="minDate"
[maxDate]="maxDate"
/>
</div>
import { BsDatepickerConfig } from'ngx-bootstrap/datepicker';
export class CardlessTransactionsComponent implements OnInit {
datePickerConfig: Partial<BsDatepickerConfig>;
privatetodayDate: Date = newDate();
minDate: Date;
maxDate: Date;
}
constructor(privatefb:FormBuilder) {
this.todayDate = newDate();
this.minDate = newDate();
this.maxDate = newDate();
this.minDate.setDate(this.minDate.getDate() - 7);
this.maxDate.setDate(this.maxDate.getDate() + 0);
at the HTML file, I think there is something need to do inside the bsValue while at the ts file, I have no idea where to change to get the output that I want which is to make it display the month's name instead of the month numeric value
You should get today's date through a formControl instead of outside it to get this working...
relevant HTML:
<div class="row">
<div class="col-sm-8">
<i class="far fa-calendar-alt"></i>
<input
id="dtpFrom"
placeholder="Datepicker"
placement="top"
class="form-control"
bsDatepicker
formControlName="dateMDY"
[bsConfig]="{dateInputFormat: 'DD MMM YYYY',containerClass: 'theme-blue'}"
[bsValue]="todayDate"
[minDate]="minDate"
[maxDate]="maxDate"
/>
</div>
</div>
working stackblitz here
Thanks for the suggestions, i have already figure it out. (make changes at the TS file)
initializeForm () {
this.cardlessForm= this.fb.group ({
dateFrom:new Date(),
dateTo:new Date ()
});
}
I just add the 'new Date ()' at the dateFrom and dateTo then i removed the code ( this.maxDate.setDate(this.maxDate.getDate() + 0);
I thought I have all the codes correct to pull a report by between dates and by group.id. But the filter message No Order Found. How to get the filter_class.php select where by group.id = index_class.php dropdown selected numeric value. I've been searching and trying everything I've learned no success.
Any help would be appreciated. If I put the group.id number in the filter_class.php select where by group.id = 4 manually, it will pull the report by that number. But it needs to pull the report based on the dropdown list on index_class.php.
I can pull the report just fine with the datepicker between dates, but I need it to pull by date and group.id number.
codes below
index_class.php
<div class="col-md-3">
<input type="text" name="from_date" id="from_date" class="form-control" placeholder="From Date" />
</div>
<div class="col-md-3">
<input type="text" name="to_date" id="to_date" class="form-control" placeholder="To Date" />
</div>
<div class="col-md-3">
<input type="button" name="filter" id="filter" value="Filter" class=".btn-mini btn-info" />
</div>
Drop down pulls data from database
------------------------------------
<div class="col-md-4">
<script>
$(document).ready(function() {
//////////////////////
$.getJSON("classes-data.php", function(return_data){
$.each(return_data.data, function(key,value){
$("#class").append("<option value=" + value.id +">"+value.name+"</option>");
});
});
//////////////////////
////////////
$('#class').change(function(){
//var st=$('#class option:selected').text();
var st=$('#class').val();
//alert(st);
});
/////////////////////
});
</script>
<select id=class id=class>
</select>
</div>
Datepicker code
----------------
<script>
$(document).ready(function(){
$.datepicker.setDefaults({
dateFormat: 'yy-mm-dd'
});
$(function(){
$("#from_date").datepicker();
$("#to_date").datepicker();
});
$('#filter').click(function(){
var from_date = $('#from_date').val();
var to_date = $('#to_date').val();
if(from_date != '' && to_date != '')
{
$.ajax({
url:"filter_class.php",
method:"POST",
data:{from_date:from_date, to_date:to_date},
success:function(data)
{
$('#order_table').html(data);
}
});
}
else
{
alert("Please Select Date");
}
});
});
</script>
filter_class.php
-------------------
$query = "
SELECT * FROM attendance_record, _person, _person_group
WHERE _person.id = attendance_record.personid AND _person_group.id = $('#class').val()
and date BETWEEN '".$_POST["from_date"]."' AND '".$_POST["to_date"]."'
ORDER BY _person_group.id ASC
";
$result = mysqli_query($conn, $query);
I'm quite new to Angular, and I've already searched the web, without finding a correct solution for my situation.
I have a dynamic form created by a *ngFor. I need to disabled the submit button if the inputs are all empty and show the alert div; but I need to enable the submit if at least one of those forms contains something different from ''.
Here is my html code
<form class="form-inline" #form="ngForm">
<div class="form-group" *ngFor="let meta of state.metaById; let i = index" style="margin: 5px">
<label>{{meta.nome}}</label>
<input type="text" class="form-control" #nome (blur)="inputInArray(nome.value, i);">
</div>
<button type="button" class="btn btn-primary" (click)="getCustomUnitaDocumentaliRow(this.param)" [disabled]="fieldNotCompiled">invia</button>
</form>
<div class="alert-notification" [hidden]="!fieldNotCompiled">
<div class="alert alert-danger">
<strong>Va compilato almeno un campo.</strong>
</div>
</div>
and here is my Typescript code
inputInArray(nome: string, indice) {
if (this.state.controlloMetaId = true) {
this.state.metadatoForm[indice] = nome;
}
// this.fieldNotCompiled = false;
for (const i in this.state.metaById) {
console.log(this.state.metadatoForm);
if (isUndefined(this.state.metadatoForm[i]) || this.state.metadatoForm[i] === '') {
this.fieldNotCompiled = true && this.fieldNotCompiled;
} else {
this.fieldNotCompiled = false && this.fieldNotCompiled;
}
console.log(this.fieldNotCompiled);
}
With this code I can check the first time a user type something in one input, but it fails if it empty one of them (or all of them)
Thanks for your time
UPDATE
Check if any input got a change that is different from empty or space, just by doing:
<input ... #nome (input)="fieldNotCompiled = !nome.value.trim()" ....>
DEMO
You can set a listener to the form changes:
#ViewChild('form') myForm: NgForm;
....
ngOnInit() {
this.myForm.valueChanges.subscribe((value: any) => {
console.log("One of the inputs has changed");
});
}
I am trying to implement a dynamic start date for a bootstrap datepicker while using vuejs. Below is an example of what I have in my code currently. Using -30d or a date formatted as 01-01-2016, but not 2016-01-01 works.
<input type="text" name="cancelDate" id="cancelDate" autocomplete="off" class="form-control form-control-small"
v-model="sale.cancelDate"
v-bind:class="{ 'has-error': !validation.cancelDate }"
v-datepicker start-date="{{sale.saleDate}}" />
<p>{{sale.saleDate}}</p>
The {{sale.saleDate}} in the p tags is accessible, and displays a date like '1/27/2016'. Changing 'start-date' to 'data-start-date' does not work. In the datepicker directive, I have...
var self = this;
$(self.el).datepicker({
startDate: self.params.startDate,
endDate: self.params.endDate,
todayBtn: "linked",
autoclose: true
});
How can I get the start-date to appear dynamically?
I post an example here:
//script.js
new Vue({
el:"#app",
data:function(){
return {
startDate: moment().subtract(7, 'days').format('MM/DD/YYYY'),
cancelDate: moment().format('MM/DD/YYYY')
}
},
ready:function(){
$('.datepicker').datepicker({ startDate: this.startDate });
}
})
// index.html
<div id="app">
<input class="datepicker" type="text" v-model="{{cancelDate}}" value="{{cancelDate}}" >
</div>
https://jsfiddle.net/nosferatu79/jfk97gp9/4/
Hope this help...