|  | 
|  | 1 | +<template> | 
|  | 2 | +	<div class="container"> | 
|  | 3 | +		<h1>Custom label, help, hint and errors (with grouping)</h1> | 
|  | 4 | +		<div class="row"> | 
|  | 5 | +			<div class="col-sm-12"> | 
|  | 6 | +				<vue-form-generator :schema="schema" :model="model" :options="formOptions" tag="section"> | 
|  | 7 | + | 
|  | 8 | +					<template slot="label" slot-scope="{ field }"> | 
|  | 9 | +						<h1>Custom label : {{ field.label }}</h1> | 
|  | 10 | +					</template> | 
|  | 11 | + | 
|  | 12 | +					<template slot="help" slot-scope="{ field }"> | 
|  | 13 | +						<span v-if='field.help' class="help"> | 
|  | 14 | +							<span @click.prevent="testClick(field.help, $event)">Custom help</span> | 
|  | 15 | +							<i class="icon"></i> | 
|  | 16 | +						</span> | 
|  | 17 | +					</template> | 
|  | 18 | + | 
|  | 19 | +					<template slot="hint" slot-scope="{ field, getValueFromOption }"> | 
|  | 20 | +						<span>Custom hint</span> | 
|  | 21 | +						<div class="hint" v-html="getValueFromOption(field, 'hint', undefined)"></div> | 
|  | 22 | +					</template> | 
|  | 23 | + | 
|  | 24 | +					<template slot="errors" slot-scope="{ errors, field, getValueFromOption }"> | 
|  | 25 | +						<span>Custom errors</span> | 
|  | 26 | +						<table class="errors help-block"> | 
|  | 27 | +							<tbody> | 
|  | 28 | +								<tr> | 
|  | 29 | +									<td v-for="(error, index) in errors" :key="index" v-html="error"></td> | 
|  | 30 | +								</tr> | 
|  | 31 | +							</tbody> | 
|  | 32 | +						</table> | 
|  | 33 | +					</template> | 
|  | 34 | + | 
|  | 35 | +				</vue-form-generator> | 
|  | 36 | +			</div> | 
|  | 37 | +		</div> | 
|  | 38 | +		<div class="row"> | 
|  | 39 | +			<div class="col-sm-12"> | 
|  | 40 | +				<pre v-if="model" v-html="prettyModel"></pre> | 
|  | 41 | +			</div> | 
|  | 42 | +		</div> | 
|  | 43 | +	</div> | 
|  | 44 | +</template> | 
|  | 45 | + | 
|  | 46 | +<script> | 
|  | 47 | +import mixinUtils from "../../mixins/utils.js"; | 
|  | 48 | +
 | 
|  | 49 | +export default { | 
|  | 50 | +	mixins: [mixinUtils], | 
|  | 51 | +
 | 
|  | 52 | +	data() { | 
|  | 53 | +		return { | 
|  | 54 | +			model: { | 
|  | 55 | +				name: "Brian Blessed", | 
|  | 56 | +				email: "brian@hawkman.mongo", | 
|  | 57 | +				others: { | 
|  | 58 | +					more: "More", | 
|  | 59 | +					things: "Things" | 
|  | 60 | +				}, | 
|  | 61 | +				single: "blah", | 
|  | 62 | +				subname: "" | 
|  | 63 | +			}, | 
|  | 64 | +
 | 
|  | 65 | +			schema: { | 
|  | 66 | +				fields: [ | 
|  | 67 | +					{ | 
|  | 68 | +						type: "group", | 
|  | 69 | +						legend: "Contact Details", | 
|  | 70 | +						tag: "div", | 
|  | 71 | +						fields: [ | 
|  | 72 | +							{ | 
|  | 73 | +								type: "input", | 
|  | 74 | +								model: "name", | 
|  | 75 | +								label: "Name", | 
|  | 76 | +								fieldOptions: { | 
|  | 77 | +									inputType: "text" | 
|  | 78 | +								}, | 
|  | 79 | +								required: true, | 
|  | 80 | +								validator: ["required"] | 
|  | 81 | +							}, | 
|  | 82 | +							{ | 
|  | 83 | +								type: "group", | 
|  | 84 | +								legend: "Subgroup", | 
|  | 85 | +								styleClasses: "subgroup", | 
|  | 86 | +								tag: "fieldset", | 
|  | 87 | +								fields: [ | 
|  | 88 | +									{ | 
|  | 89 | +										type: "input", | 
|  | 90 | +										model: "subname", | 
|  | 91 | +										label: "Name", | 
|  | 92 | +										fieldOptions: { | 
|  | 93 | +											inputType: "text" | 
|  | 94 | +										}, | 
|  | 95 | +										required: true, | 
|  | 96 | +										validator: ["required"] | 
|  | 97 | +									} | 
|  | 98 | +								] | 
|  | 99 | +							}, | 
|  | 100 | +							{ | 
|  | 101 | +								type: "input", | 
|  | 102 | +								model: "email", | 
|  | 103 | +								label: "Email", | 
|  | 104 | +								fieldOptions: { | 
|  | 105 | +									inputType: "email" | 
|  | 106 | +								} | 
|  | 107 | +							} | 
|  | 108 | +						] | 
|  | 109 | +					}, | 
|  | 110 | +					{ | 
|  | 111 | +						type: "input", | 
|  | 112 | +						model: "single", | 
|  | 113 | +						label: "Single field (without group)", | 
|  | 114 | +						fieldOptions: { | 
|  | 115 | +							inputType: "text" | 
|  | 116 | +						}, | 
|  | 117 | +						required: true, | 
|  | 118 | +						validator: ["string"] | 
|  | 119 | +					}, | 
|  | 120 | +					{ | 
|  | 121 | +						type: "group", | 
|  | 122 | +						legend: "Other Details", | 
|  | 123 | +						fields: [ | 
|  | 124 | +							{ | 
|  | 125 | +								type: "input", | 
|  | 126 | +								model: "others.more", | 
|  | 127 | +								label: "More", | 
|  | 128 | +								fieldOptions: { | 
|  | 129 | +									inputType: "text" | 
|  | 130 | +								} | 
|  | 131 | +							}, | 
|  | 132 | +							{ | 
|  | 133 | +								type: "input", | 
|  | 134 | +								model: "others.things", | 
|  | 135 | +								label: "Things", | 
|  | 136 | +								fieldOptions: { | 
|  | 137 | +									inputType: "text" | 
|  | 138 | +								} | 
|  | 139 | +							} | 
|  | 140 | +						] | 
|  | 141 | +					} | 
|  | 142 | +				] | 
|  | 143 | +			}, | 
|  | 144 | +
 | 
|  | 145 | +			formOptions: { | 
|  | 146 | +				validateAfterLoad: true, | 
|  | 147 | +				validateAfterChanged: true, | 
|  | 148 | +				fieldIdPrefix: "frm1-" | 
|  | 149 | +			} | 
|  | 150 | +		}; | 
|  | 151 | +	}, | 
|  | 152 | +
 | 
|  | 153 | +	methods: { | 
|  | 154 | +		testClick(helpText, event) { | 
|  | 155 | +			console.log(helpText, event); | 
|  | 156 | +		} | 
|  | 157 | +	}, | 
|  | 158 | +
 | 
|  | 159 | +	created() { | 
|  | 160 | +		window.app = this; | 
|  | 161 | +	} | 
|  | 162 | +}; | 
|  | 163 | +</script> | 
|  | 164 | + | 
|  | 165 | +<style lang="scss"> | 
|  | 166 | +@import "../../style.scss"; | 
|  | 167 | +.field-group { | 
|  | 168 | +	border: 2px solid #bbb; | 
|  | 169 | +	padding: 8px; | 
|  | 170 | +	border-radius: 4px; | 
|  | 171 | +} | 
|  | 172 | +.subgroup { | 
|  | 173 | +	border-color: goldenrod; | 
|  | 174 | +	legend { | 
|  | 175 | +		color: #00268d; | 
|  | 176 | +	} | 
|  | 177 | +} | 
|  | 178 | +</style> | 
0 commit comments