update components to emit valid on field-change and use in TO form
This commit is contained in:
parent
414e5989f5
commit
56bc9dd4e5
@ -24,6 +24,10 @@ export default {
|
|||||||
type: Boolean,
|
type: Boolean,
|
||||||
default: false,
|
default: false,
|
||||||
},
|
},
|
||||||
|
optional: {
|
||||||
|
type: Boolean,
|
||||||
|
default: true,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
data: function() {
|
data: function() {
|
||||||
@ -35,6 +39,14 @@ export default {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
created: function() {
|
||||||
|
emitEvent('field-mount', this, {
|
||||||
|
optional: this.optional,
|
||||||
|
name: this.name,
|
||||||
|
valid: this.isDateValid,
|
||||||
|
})
|
||||||
|
},
|
||||||
|
|
||||||
watch: {
|
watch: {
|
||||||
month(newMonth, oldMonth) {
|
month(newMonth, oldMonth) {
|
||||||
if (!!newMonth && newMonth.length > 2) {
|
if (!!newMonth && newMonth.length > 2) {
|
||||||
@ -84,7 +96,7 @@ export default {
|
|||||||
isYearValid: function() {
|
isYearValid: function() {
|
||||||
// Emit a change event
|
// Emit a change event
|
||||||
var valid = parseInt(this.year) >= 1
|
var valid = parseInt(this.year) >= 1
|
||||||
this._emitChange('year', this.year, valid)
|
// this._emitChange('year', this.year, valid)
|
||||||
return valid
|
return valid
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -106,9 +118,9 @@ export default {
|
|||||||
|
|
||||||
isDateValid: function() {
|
isDateValid: function() {
|
||||||
return (
|
return (
|
||||||
this.day &&
|
!!this.day &&
|
||||||
this.month &&
|
!!this.month &&
|
||||||
this.year &&
|
!!this.year &&
|
||||||
this.isDayValid &&
|
this.isDayValid &&
|
||||||
this.isMonthValid &&
|
this.isMonthValid &&
|
||||||
this.isYearValid &&
|
this.isYearValid &&
|
||||||
@ -141,13 +153,19 @@ export default {
|
|||||||
},
|
},
|
||||||
|
|
||||||
methods: {
|
methods: {
|
||||||
_emitChange: function(name, value, valid) {
|
onInput: function(e) {
|
||||||
|
console.log('emitting event')
|
||||||
emitEvent('field-change', this, {
|
emitEvent('field-change', this, {
|
||||||
value: value,
|
value: e.target.value,
|
||||||
name: name,
|
name: this.name,
|
||||||
watch: this.watch,
|
watch: this.watch,
|
||||||
|
valid: this.isDateValid,
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
|
||||||
|
_emitChange: function(name, value, valid) {
|
||||||
|
emitEvent('field-change', this, { value, name })
|
||||||
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
render: function(createElement) {
|
render: function(createElement) {
|
||||||
|
@ -31,6 +31,7 @@ export default {
|
|||||||
type: Boolean,
|
type: Boolean,
|
||||||
default: false,
|
default: false,
|
||||||
},
|
},
|
||||||
|
optional: Boolean,
|
||||||
},
|
},
|
||||||
|
|
||||||
data: function() {
|
data: function() {
|
||||||
@ -124,7 +125,7 @@ export default {
|
|||||||
// Emit a change event
|
// Emit a change event
|
||||||
emitEvent('field-change', this, {
|
emitEvent('field-change', this, {
|
||||||
value: this._rawValue(value),
|
value: this._rawValue(value),
|
||||||
valid,
|
valid: this._isValid(value),
|
||||||
name: this.name,
|
name: this.name,
|
||||||
watch: this.watch,
|
watch: this.watch,
|
||||||
})
|
})
|
||||||
|
@ -17,6 +17,7 @@ export default {
|
|||||||
},
|
},
|
||||||
|
|
||||||
props: {
|
props: {
|
||||||
|
name: String,
|
||||||
initialData: {
|
initialData: {
|
||||||
type: String,
|
type: String,
|
||||||
},
|
},
|
||||||
@ -27,6 +28,10 @@ export default {
|
|||||||
type: Boolean,
|
type: Boolean,
|
||||||
default: false,
|
default: false,
|
||||||
},
|
},
|
||||||
|
optional: {
|
||||||
|
type: Boolean,
|
||||||
|
default: true,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
data: function() {
|
data: function() {
|
||||||
@ -38,6 +43,14 @@ export default {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
created: function() {
|
||||||
|
emitEvent('field-mount', this, {
|
||||||
|
optional: this.optional,
|
||||||
|
name: this.name,
|
||||||
|
valid: this.hasAttachment,
|
||||||
|
})
|
||||||
|
},
|
||||||
|
|
||||||
methods: {
|
methods: {
|
||||||
addAttachment: function(e) {
|
addAttachment: function(e) {
|
||||||
this.attachment = e.target.value
|
this.attachment = e.target.value
|
||||||
@ -48,6 +61,7 @@ export default {
|
|||||||
value: e.target.value,
|
value: e.target.value,
|
||||||
name: this.name,
|
name: this.name,
|
||||||
watch: this.watch,
|
watch: this.watch,
|
||||||
|
valid: this.hasAttachment,
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
removeAttachment: function(e) {
|
removeAttachment: function(e) {
|
||||||
|
@ -27,6 +27,8 @@ export default {
|
|||||||
handleFieldMount: function(event) {
|
handleFieldMount: function(event) {
|
||||||
const { name, optional, valid } = event
|
const { name, optional, valid } = event
|
||||||
this.fields[name] = optional || valid
|
this.fields[name] = optional || valid
|
||||||
|
const formValid = this.validateForm()
|
||||||
|
this.invalid = !formValid
|
||||||
},
|
},
|
||||||
|
|
||||||
validateForm: function() {
|
validateForm: function() {
|
||||||
|
@ -6,15 +6,18 @@
|
|||||||
description=field.description,
|
description=field.description,
|
||||||
mindate=None,
|
mindate=None,
|
||||||
maxdate=None,
|
maxdate=None,
|
||||||
watch=False) -%}
|
watch=False,
|
||||||
|
optional=True) -%}
|
||||||
|
|
||||||
<date-selector
|
<date-selector
|
||||||
{% if maxdate %}maxdate="{{ maxdate.strftime("%Y-%m-%d") }}"{% endif %}
|
{% if maxdate %}maxdate="{{ maxdate.strftime("%Y-%m-%d") }}"{% endif %}
|
||||||
{% if mindate %}mindate="{{ mindate.strftime("%Y-%m-%d") }}"{% endif %}
|
{% if mindate %}mindate="{{ mindate.strftime("%Y-%m-%d") }}"{% endif %}
|
||||||
|
name-tag='{{ field.name }}'
|
||||||
initialmonth="{{ field.data.month }}"
|
initialmonth="{{ field.data.month }}"
|
||||||
initialday="{{ field.data.day }}"
|
initialday="{{ field.data.day }}"
|
||||||
initialyear="{{ field.data.year }}"
|
initialyear="{{ field.data.year }}"
|
||||||
v-bind:watch='{{ watch | string | lower }}'
|
v-bind:watch='{{ watch | string | lower }}'
|
||||||
|
:optional='{{ optional | string | lower }}'
|
||||||
inline-template>
|
inline-template>
|
||||||
|
|
||||||
<fieldset class="usa-input date-picker" v-bind:class="{ 'usa-input--success': isDateValid }">
|
<fieldset class="usa-input date-picker" v-bind:class="{ 'usa-input--success': isDateValid }">
|
||||||
@ -29,7 +32,7 @@
|
|||||||
</legend>
|
</legend>
|
||||||
|
|
||||||
<div class="date-picker-component">
|
<div class="date-picker-component">
|
||||||
<input name="{{ field.name }}" v-bind:value="formattedDate" type="hidden" />
|
<input name="{{ field.name }}" v-bind:value="formattedDate" v-on:change="onInput" type="hidden" />
|
||||||
|
|
||||||
<div class="usa-form-group usa-form-group-month">
|
<div class="usa-form-group usa-form-group-month">
|
||||||
<label>Month</label>
|
<label>Month</label>
|
||||||
@ -54,6 +57,7 @@
|
|||||||
v-bind:class="{ 'usa-input-error': (day && !isDayValid) }"
|
v-bind:class="{ 'usa-input-error': (day && !isDayValid) }"
|
||||||
v-bind:max="daysMaxCalculation"
|
v-bind:max="daysMaxCalculation"
|
||||||
v-model="day"
|
v-model="day"
|
||||||
|
v-on:change="onInput"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@ -66,6 +70,7 @@
|
|||||||
v-model="year"
|
v-model="year"
|
||||||
{% if maxdate %}max="{{ maxdate.year }}"{% endif %}
|
{% if maxdate %}max="{{ maxdate.year }}"{% endif %}
|
||||||
{% if mindate %}min="{{ mindate.year }}"{% endif %}
|
{% if mindate %}min="{{ mindate.year }}"{% endif %}
|
||||||
|
v-on:change="onInput"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
initial_value='',
|
initial_value='',
|
||||||
classes='',
|
classes='',
|
||||||
noMaxWidth=False,
|
noMaxWidth=False,
|
||||||
optional=False,
|
optional=True,
|
||||||
showLabel=True,
|
showLabel=True,
|
||||||
watch=False) -%}
|
watch=False) -%}
|
||||||
|
|
||||||
|
@ -9,6 +9,8 @@
|
|||||||
v-bind:initial-errors='true'
|
v-bind:initial-errors='true'
|
||||||
{% endif %}
|
{% endif %}
|
||||||
v-bind:watch='{{ watch | string | lower }}'
|
v-bind:watch='{{ watch | string | lower }}'
|
||||||
|
name='{{ field.name }}'
|
||||||
|
:optional='false'
|
||||||
>
|
>
|
||||||
<div>
|
<div>
|
||||||
<div v-show="hasAttachment" class="uploaded-file">
|
<div v-show="hasAttachment" class="uploaded-file">
|
||||||
|
@ -87,8 +87,8 @@
|
|||||||
</fieldset>
|
</fieldset>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{{ DatePicker(fields.start_date, watch=True) }}
|
{{ DatePicker(fields.start_date, watch=True, optional=False) }}
|
||||||
{{ DatePicker(fields.end_date, watch=True) }}
|
{{ DatePicker(fields.end_date, watch=True, optional=False) }}
|
||||||
{{ TextInput(fields.obligated_amount, validation='dollars', watch=True) }}
|
{{ TextInput(fields.obligated_amount, validation='dollars', watch=True) }}
|
||||||
</div>
|
</div>
|
||||||
</clin-fields>
|
</clin-fields>
|
||||||
@ -117,7 +117,14 @@
|
|||||||
{% call StickyCTA(text="Add Funding") %}
|
{% call StickyCTA(text="Add Funding") %}
|
||||||
<span class="action-group">
|
<span class="action-group">
|
||||||
<!-- todo: implement the review button -->
|
<!-- todo: implement the review button -->
|
||||||
<input type="submit" formaction="{{ review_action }}" tabindex="0" value="Review task order" form="new-task-order" class="usa-button usa-button-primary">
|
<input
|
||||||
|
type="submit"
|
||||||
|
formaction="{{ review_action }}"
|
||||||
|
tabindex="0"
|
||||||
|
:disabled="invalid"
|
||||||
|
value="Review task order"
|
||||||
|
form="new-task-order"
|
||||||
|
class="usa-button usa-button-primary">
|
||||||
<input
|
<input
|
||||||
type="submit"
|
type="submit"
|
||||||
class="usa-button usa-button-secondary"
|
class="usa-button usa-button-secondary"
|
||||||
@ -145,7 +152,7 @@
|
|||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col">
|
<div class="col">
|
||||||
<div class="h1">Add your task order</div>
|
<div class="h1">Add your task order</div>
|
||||||
{{ TextInput(form.number, validation='taskOrderNumber') }}
|
{{ TextInput(form.number, validation='taskOrderNumber', optional=False) }}
|
||||||
|
|
||||||
<hr>
|
<hr>
|
||||||
|
|
||||||
@ -167,7 +174,7 @@
|
|||||||
<div>
|
<div>
|
||||||
<div class="form-row">
|
<div class="form-row">
|
||||||
<div class="form-col form-col--two-thirds">
|
<div class="form-col form-col--two-thirds">
|
||||||
<optionsinput :name="'clins-' + clinIndex + '-jedi_clin_type'" :watch='true' inline-template>
|
<optionsinput :name="'clins-' + clinIndex + '-jedi_clin_type'" :watch='true' :optional='false' inline-template>
|
||||||
<div class="usa-input">
|
<div class="usa-input">
|
||||||
<fieldset data-ally-disabled="true" class="usa-input__choices" v-on:change="onInput">
|
<fieldset data-ally-disabled="true" class="usa-input__choices" v-on:change="onInput">
|
||||||
<legend>
|
<legend>
|
||||||
@ -233,7 +240,7 @@
|
|||||||
</fieldset>
|
</fieldset>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<date-selector :name-tag="'clins-' + clinIndex + '-start_date'" :watch='true' inline-template>
|
<date-selector :name-tag="'clins-' + clinIndex + '-start_date'" :watch='true' :optional='false' inline-template>
|
||||||
<fieldset class="usa-input date-picker" v-bind:class="{ 'usa-input--success': isDateValid }">
|
<fieldset class="usa-input date-picker" v-bind:class="{ 'usa-input--success': isDateValid }">
|
||||||
<legend>
|
<legend>
|
||||||
<div class="usa-input__title">
|
<div class="usa-input__title">
|
||||||
@ -242,7 +249,7 @@
|
|||||||
</legend>
|
</legend>
|
||||||
|
|
||||||
<div class="date-picker-component">
|
<div class="date-picker-component">
|
||||||
<input :name="name" v-bind:value="formattedDate" type="hidden" />
|
<input :name="name" v-bind:value="formattedDate" v-on:change="onInput" type="hidden" />
|
||||||
|
|
||||||
<div class="usa-form-group usa-form-group-month">
|
<div class="usa-form-group usa-form-group-month">
|
||||||
<label>Month</label>
|
<label>Month</label>
|
||||||
@ -254,6 +261,7 @@
|
|||||||
type="number"
|
type="number"
|
||||||
v-bind:class="{ 'usa-input-error': (month && !isMonthValid) }"
|
v-bind:class="{ 'usa-input-error': (month && !isMonthValid) }"
|
||||||
v-model="month"
|
v-model="month"
|
||||||
|
v-on:change="onInput"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@ -267,6 +275,7 @@
|
|||||||
v-bind:class="{ 'usa-input-error': (day && !isDayValid) }"
|
v-bind:class="{ 'usa-input-error': (day && !isDayValid) }"
|
||||||
v-bind:max="daysMaxCalculation"
|
v-bind:max="daysMaxCalculation"
|
||||||
v-model="day"
|
v-model="day"
|
||||||
|
v-on:change="onInput"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@ -277,6 +286,7 @@
|
|||||||
maxlength="4"
|
maxlength="4"
|
||||||
type="number"
|
type="number"
|
||||||
v-model="year"
|
v-model="year"
|
||||||
|
v-on:change="onInput"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
@ -288,7 +298,7 @@
|
|||||||
</fieldset>
|
</fieldset>
|
||||||
</date-selector>
|
</date-selector>
|
||||||
|
|
||||||
<date-selector :name-tag="'clins-' + clinIndex + '-end_date'" :watch='true' inline-template>
|
<date-selector :name-tag="'clins-' + clinIndex + '-end_date'" :watch='true' :optional='false' inline-template>
|
||||||
<fieldset class="usa-input date-picker" v-bind:class="{ 'usa-input--success': isDateValid }">
|
<fieldset class="usa-input date-picker" v-bind:class="{ 'usa-input--success': isDateValid }">
|
||||||
<legend>
|
<legend>
|
||||||
<div class="usa-input__title">
|
<div class="usa-input__title">
|
||||||
@ -297,7 +307,7 @@
|
|||||||
</legend>
|
</legend>
|
||||||
|
|
||||||
<div class="date-picker-component">
|
<div class="date-picker-component">
|
||||||
<input :name="name" v-bind:value="formattedDate" type="hidden" />
|
<input :name="name" v-bind:value="formattedDate" v-on:change="onInput" type="hidden" />
|
||||||
|
|
||||||
<div class="usa-form-group usa-form-group-month">
|
<div class="usa-form-group usa-form-group-month">
|
||||||
<label>Month</label>
|
<label>Month</label>
|
||||||
@ -309,6 +319,7 @@
|
|||||||
type="number"
|
type="number"
|
||||||
v-bind:class="{ 'usa-input-error': (month && !isMonthValid) }"
|
v-bind:class="{ 'usa-input-error': (month && !isMonthValid) }"
|
||||||
v-model="month"
|
v-model="month"
|
||||||
|
v-on:change="onInput"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@ -322,6 +333,7 @@
|
|||||||
v-bind:class="{ 'usa-input-error': (day && !isDayValid) }"
|
v-bind:class="{ 'usa-input-error': (day && !isDayValid) }"
|
||||||
v-bind:max="daysMaxCalculation"
|
v-bind:max="daysMaxCalculation"
|
||||||
v-model="day"
|
v-model="day"
|
||||||
|
v-on:change="onInput"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@ -332,6 +344,7 @@
|
|||||||
maxlength="4"
|
maxlength="4"
|
||||||
type="number"
|
type="number"
|
||||||
v-model="year"
|
v-model="year"
|
||||||
|
v-on:change="onInput"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user