Skip to content

Better accessibility labels #105

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions src/fields/abstractField.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,29 @@ export default {
this.$set(this.schema, "errors", []); // Be reactive
else
this.schema.errors.splice(0); // Clear
},

getFieldID(schema) {
// Try to get a reasonable default id from the schema,
// then slugify it.
if (typeof schema.id !== "undefined") {
// If an ID's been explicitly set, use it unchanged
return schema.id;
} else {
return (schema.inputName || schema.label || schema.model)
.toString()
.trim()
.toLowerCase()
// Spaces to dashes
.replace(/ /g, "-")
// Multiple dashes to one
.replace(/-{2,}/g, "-")
// Remove leading & trailing dashes
.replace(/^-+|-+$/g, "")
// Remove anything that isn't a (English/ASCII) letter or number.
.replace(/([^a-zA-Z0-9\._-]+)/g, "")
;
}
}
}
};
2 changes: 1 addition & 1 deletion src/fields/fieldCleave.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template lang="jade">
input.form-control(type="text", v-model="value", :autocomplete="schema.autocomplete", :disabled="disabled", :placeholder="schema.placeholder", :readonly="schema.readonly", :name="schema.inputName")
input.form-control(type="text", v-model="value", :autocomplete="schema.autocomplete", :disabled="disabled", :placeholder="schema.placeholder", :readonly="schema.readonly", :name="schema.inputName", :id="getFieldID(schema)")
</template>

<script>
Expand Down
6 changes: 3 additions & 3 deletions src/fields/fieldDateTimePicker.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<template lang="jade">
.input-group.date
input.form-control(type="text", v-model="value", :autocomplete="schema.autocomplete", :disabled="disabled", :placeholder="schema.placeholder", :readonly="schema.readonly", :name="schema.inputName")
input.form-control(type="text", v-model="value", :autocomplete="schema.autocomplete", :disabled="disabled", :placeholder="schema.placeholder", :readonly="schema.readonly", :name="schema.inputName", :id="getFieldID(schema)")
span.input-group-addon
span.glyphicon.glyphicon-calendar
</template>
Expand All @@ -19,7 +19,7 @@
methods: {

getDateFormat() {
if (this.schema.dateTimePickerOptions && this.schema.dateTimePickerOptions.format)
if (this.schema.dateTimePickerOptions && this.schema.dateTimePickerOptions.format)
return this.schema.dateTimePickerOptions.format;
else
return inputFormat;
Expand Down Expand Up @@ -62,7 +62,7 @@
if ($.fn.datetimepicker){
$(this.$el).data("DateTimePicker").destroy();
}
}
}
};
</script>

Expand Down
8 changes: 4 additions & 4 deletions src/fields/fieldGoogleAddress.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template lang="jade">
input.form-control(type="text", v-model="value", :autocomplete="schema.autocomplete", :disabled="disabled", :placeholder="schema.placeholder", :readonly="schema.readonly", :name="schema.inputName", debounce="500", @focus="geolocate()")
input.form-control(type="text", v-model="value", :autocomplete="schema.autocomplete", :disabled="disabled", :placeholder="schema.placeholder", :readonly="schema.readonly", :name="schema.inputName", debounce="500", @focus="geolocate()", :id="getFieldID(schema)")
</template>

<script>
Expand Down Expand Up @@ -59,7 +59,7 @@
if (place) {

this.value = place.formatted_address;

let data = {};
if (place.address_components !== undefined) {
for (let i = 0; i < place.address_components.length; i++) {
Expand All @@ -70,12 +70,12 @@
}

}

// Call event in schema
if (isFunction(this.schema.onPlaceChanged))
this.schema.onPlaceChanged(this.value, data, place, this.model, this.schema);
}
},
},

/**
* Get the user location.
Expand Down
7 changes: 4 additions & 3 deletions src/fields/fieldInput.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<template lang="jade">
.wrapper
input.form-control(
:type="schema.inputType",
:id="getFieldID(schema)",
:type="schema.inputType",
:value="value",
@input="value = $event.target.value",
number="schema.inputType == 'number'"
Expand Down Expand Up @@ -62,12 +63,12 @@
return new Date(value).getTime();
}
}

return value;
}
}
};

</script>

<style lang="sass">
Expand Down
2 changes: 1 addition & 1 deletion src/fields/fieldLabel.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template lang="jade">
span {{ value }}
span(:id="getFieldID(schema)") {{ value }}
</template>

<script>
Expand Down
4 changes: 2 additions & 2 deletions src/fields/fieldMasked.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template lang="jade">
input.form-control(type="text", v-model="value", :autocomplete="schema.autocomplete", :disabled="disabled", :placeholder="schema.placeholder", :readonly="schema.readonly", :name="schema.inputName")
input.form-control(type="text", v-model="value", :autocomplete="schema.autocomplete", :disabled="disabled", :placeholder="schema.placeholder", :readonly="schema.readonly", :name="schema.inputName", :id="getFieldID(schema)")
</template>

<script>
Expand All @@ -22,7 +22,7 @@
beforeDestroy() {
if ($.fn.mask)
$(this.$el).unmask();
}
}
};
</script>

Expand Down
6 changes: 3 additions & 3 deletions src/fields/fieldSelect.vue
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<template lang="jade">
select.form-control(v-model="value", :disabled="disabled", :name="schema.inputName")
select.form-control(v-model="value", :disabled="disabled", :name="schema.inputName", :id="getFieldID(schema)")
option(:disabled="schema.required", :value="null", :selected="value == undefined") {{ selectOptions.noneSelectedText || "&lt;Nothing selected&gt;" }}
option(v-for="item in items", :value="getItemID(item)") {{ getItemName(item) }}
</template>

<script>
import {isObject} from "lodash";
import abstractField from "./abstractField";

export default {
mixins: [ abstractField ],

Expand All @@ -22,7 +22,7 @@
return values.apply(this, [this.model, this.schema]);
} else
return values;
}
}
},

methods: {
Expand Down
4 changes: 2 additions & 2 deletions src/fields/fieldSpectrum.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template lang="jade">
input(type="text", :autocomplete="schema.autocomplete", :disabled="disabled", :placeholder="schema.placeholder", :readonly="schema.readonly", :name="schema.inputName")
input(type="text", :autocomplete="schema.autocomplete", :disabled="disabled", :placeholder="schema.placeholder", :readonly="schema.readonly", :name="schema.inputName", :id="getFieldID(schema)")
</template>

<script>
Expand All @@ -15,7 +15,7 @@
};
},

watch: {
watch: {
model() {
if ($.fn.spectrum) {
this.picker.spectrum("set", this.value);
Expand Down
16 changes: 8 additions & 8 deletions src/fields/fieldSwitch.vue
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
<template lang="jade">
label
input(type="checkbox", v-model="value", :autocomplete="schema.autocomplete", :disabled="disabled", :name="schema.inputName")
span.label(:data-on="schema.textOn || 'On'", :data-off="schema.textOff || 'Off'")
input(type="checkbox", v-model="value", :autocomplete="schema.autocomplete", :disabled="disabled", :name="schema.inputName", :id="getFieldID(schema)")
span.label(:data-on="schema.textOn || 'On'", :data-off="schema.textOff || 'Off'", :for="getFieldID(schema)")
span.handle
</template>

<script>
import abstractField from "./abstractField";

export default {
mixins: [ abstractField ],

methods: {

formatValueToField(value) {
if (value != null && this.schema.valueOn)
return value == this.schema.valueOn;
Expand All @@ -29,7 +29,7 @@
}

return value;
}
}
}
};
</script>
Expand All @@ -39,7 +39,7 @@
$field-switch-width: 120px;
$field-switch-height: 30px;

.vue-form-generator .field-switch {
.vue-form-generator .field-switch {

.field-wrap label {
position: relative;
Expand Down Expand Up @@ -132,11 +132,11 @@
left: calc(100% - ($field-switch-height - 1px));
box-shadow: -1px 1px 5px rgba(0, 0, 0, 0.2);
}

/* Transition
========================== */
.label, .handle {
transition: all 0.3s ease;
}
}
</style>
</style>
13 changes: 11 additions & 2 deletions src/fields/fieldTextArea.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
<template lang="jade">
textarea.form-control(v-model="value", :disabled="disabled", :maxlength="schema.max", :minlength="schema.min", :placeholder="schema.placeholder", :readonly="schema.readonly", :rows="schema.rows || 2", :name="schema.inputName")
textarea.form-control(
v-model="value",
:id="getFieldID(schema)",
:disabled="disabled",
:maxlength="schema.max",
:minlength="schema.min",
:placeholder="schema.placeholder",
:readonly="schema.readonly",
:rows="schema.rows || 2",
:name="schema.inputName")
</template>

<script>
Expand All @@ -8,7 +17,7 @@
export default {
mixins: [ abstractField ]
};

</script>


Expand Down
Loading