Skip to content

Better accessibility labels - to master #201

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

Merged
merged 10 commits into from
May 24, 2017
Merged
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
35 changes: 31 additions & 4 deletions src/fields/abstractField.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export default {
if (isFunction(this.schema.set)) {
this.schema.set(this.model, newValue);
changed = true;

} else if (this.schema.model) {
this.setModelValueByPath(this.schema.model, newValue);
changed = true;
Expand All @@ -68,7 +68,7 @@ export default {

if (this.$parent.options && this.$parent.options.validateAfterChanged === true){
this.validate();
}
}
}
}
}
Expand Down Expand Up @@ -133,7 +133,7 @@ export default {
setModelValueByPath(path, value) {
// convert array indexes to properties
let s = path.replace(/\[(\w+)\]/g, ".$1");

// strip a leading dot
s = s.replace(/^\./, "");

Expand All @@ -157,9 +157,36 @@ export default {
this.$root.$set(o, k, value);
return;
}

++i;
}
},

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 the slugified version of either:
return (schema.inputName || schema.label || schema.model)
// NB: This is a very simple, conservative, slugify function,
// avoiding extra dependencies.
.toString()
.trim()
.toLowerCase()
// Spaces & underscores 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, number or dash.
.replace(/([^a-zA-Z0-9-]+)/g, "")
;
}
}

}
};
7 changes: 4 additions & 3 deletions src/fields/core/fieldInput.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<template lang="pug">
.wrapper
input.form-control(
:type="schema.inputType",
:id="getFieldID(schema)",
:type="schema.inputType",
:value="value",
@input="value = $event.target.value",
@change="onChange",
Expand Down Expand Up @@ -74,12 +75,12 @@
return Number(value);
}
}

return value;
}
}
};

</script>

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

<script>
Expand Down
2 changes: 1 addition & 1 deletion src/fields/core/fieldSelect.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template lang="pug">
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>
Expand Down
11 changes: 10 additions & 1 deletion src/fields/core/fieldTextArea.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
<template lang="pug">
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 Down
2 changes: 1 addition & 1 deletion src/fields/optional/fieldCleave.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template lang="pug">
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/optional/fieldDateTimePicker.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<template lang="pug">
.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 @@ -47,7 +47,7 @@
if (window.$ && window.$.fn.datetimepicker){
$(this.$el).data("DateTimePicker").destroy();
}
}
}
};
</script>

Expand Down
8 changes: 4 additions & 4 deletions src/fields/optional/fieldGoogleAddress.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template lang="pug">
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
2 changes: 1 addition & 1 deletion src/fields/optional/fieldMasked.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template lang="pug">
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
2 changes: 1 addition & 1 deletion src/fields/optional/fieldSpectrum.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template lang="pug">
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 Down
4 changes: 2 additions & 2 deletions src/fields/optional/fieldSwitch.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<template lang="pug">
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>

Expand Down
Loading