Skip to content

Commit

Permalink
feat(editor): add title attribute to all Editors (#156)
Browse files Browse the repository at this point in the history
  • Loading branch information
ghiscoding committed Apr 7, 2019
1 parent 4c887c6 commit 6e0d125
Show file tree
Hide file tree
Showing 11 changed files with 29 additions and 7 deletions.
3 changes: 2 additions & 1 deletion src/aurelia-slickgrid/editors/autoCompleteEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,11 @@ export class AutoCompleteEditor implements Editor {
init(): void {
const columnId = this.columnDef && this.columnDef.id;
const placeholder = this.columnEditor && this.columnEditor.placeholder || '';
const title = this.columnEditor && this.columnEditor.title || '';
this.labelName = this.customStructure && this.customStructure.label || 'label';
this.valueName = this.customStructure && this.customStructure.value || 'value';

this.$input = $(`<input type="text" class="editor-text editor-${columnId}" placeholder="${placeholder}" />`)
this.$input = $(`<input type="text" class="editor-text editor-${columnId}" placeholder="${placeholder}" title="${title}" />`)
.appendTo(this.args.container)
.on('keydown.nav', (event: JQueryEventObject) => {
this._lastInputEvent = event;
Expand Down
3 changes: 2 additions & 1 deletion src/aurelia-slickgrid/editors/checkboxEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ export class CheckboxEditor implements Editor {

init(): void {
const columnId = this.columnDef && this.columnDef.id;
this.$input = $(`<input type="checkbox" value="true" class="editor-checkbox editor-${columnId}" />`);
const title = this.columnEditor && this.columnEditor.title || '';
this.$input = $(`<input type="checkbox" value="true" class="editor-checkbox editor-${columnId}" title="${title}" />`);
this.$input.appendTo(this.args.container);
this.$input.focus();

Expand Down
3 changes: 2 additions & 1 deletion src/aurelia-slickgrid/editors/dateEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export class DateEditor implements Editor {
if (this.args && this.args.column) {
const columnId = this.columnDef && this.columnDef.id;
const placeholder = this.columnEditor && this.columnEditor.placeholder || '';
const title = this.columnEditor && this.columnEditor.title || '';
this.defaultDate = (this.args.item) ? this.args.item[this.args.column.field] : null;
const inputFormat = mapFlatpickrDateFormatWithFieldType(this.args.column.type || FieldType.dateIso);
const outputFormat = mapFlatpickrDateFormatWithFieldType(this.args.column.outputType || FieldType.dateUtc);
Expand All @@ -65,7 +66,7 @@ export class DateEditor implements Editor {
// merge options with optional user's custom options
const pickerMergedOptions = { ...pickerOptions, ...this.columnEditor.editorOptions };

this.$input = $(`<input type="text" data-defaultDate="${this.defaultDate}" class="editor-text editor-${columnId} flatpickr" placeholder="${placeholder}" />`);
this.$input = $(`<input type="text" data-defaultDate="${this.defaultDate}" class="editor-text editor-${columnId} flatpickr" placeholder="${placeholder}" title="${title}" />`);
this.$input.appendTo(this.args.container);
this.flatInstance = (flatpickr && this.$input[0] && typeof this.$input[0].flatpickr === 'function') ? this.$input[0].flatpickr(pickerMergedOptions) : null;
this.show();
Expand Down
3 changes: 2 additions & 1 deletion src/aurelia-slickgrid/editors/floatEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,9 @@ export class FloatEditor implements Editor {
init(): void {
const columnId = this.columnDef && this.columnDef.id;
const placeholder = this.columnEditor && this.columnEditor.placeholder || '';
const title = this.columnEditor && this.columnEditor.title || '';

this.$input = $(`<input type="number" class="editor-text editor-${columnId}" placeholder="${placeholder}" step="${this.getInputDecimalSteps()}" />`)
this.$input = $(`<input type="number" class="editor-text editor-${columnId}" placeholder="${placeholder}" title="${title}" step="${this.getInputDecimalSteps()}" />`)
.appendTo(this.args.container)
.on('keydown.nav', (event: JQueryEventObject) => {
this._lastInputEvent = event;
Expand Down
3 changes: 2 additions & 1 deletion src/aurelia-slickgrid/editors/integerEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,9 @@ export class IntegerEditor implements Editor {
init(): void {
const columnId = this.columnDef && this.columnDef.id;
const placeholder = this.columnEditor && this.columnEditor.placeholder || '';
const title = this.columnEditor && this.columnEditor.title || '';

this.$input = $(`<input type="number" class="editor-text editor-${columnId}" placeholder="${placeholder}" />`)
this.$input = $(`<input type="number" class="editor-text editor-${columnId}" placeholder="${placeholder}" title="${title}" />`)
.appendTo(this.args.container)
.on('keydown.nav', (event: JQueryEventObject) => {
this._lastInputEvent = event;
Expand Down
3 changes: 2 additions & 1 deletion src/aurelia-slickgrid/editors/longTextEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,11 @@ export class LongTextEditor implements Editor {
const cancelText = this.i18n.tr('CANCEL') || Constants.TEXT_CANCEL;
const saveText = this.i18n.tr('SAVE') || Constants.TEXT_SAVE;
const placeholder = this.columnEditor && this.columnEditor.placeholder || '';
const title = this.columnEditor && this.columnEditor.title || '';
const $container = $('body');

this.$wrapper = $(`<div class="slick-large-editor-text editor-${columnId}" />`).appendTo($container);
this.$textarea = $(`<textarea hidefocus rows="5" placeholder="${placeholder}">`).appendTo(this.$wrapper);
this.$textarea = $(`<textarea hidefocus rows="5" placeholder="${placeholder}" title="${title}">`).appendTo(this.$wrapper);

// aurelia-slickgrid does not get the focus out event for some reason
// so register it here
Expand Down
3 changes: 3 additions & 0 deletions src/aurelia-slickgrid/editors/sliderEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ export class SliderEditor implements Editor {
*/
private buildTemplateHtmlString() {
const columnId = this.columnDef && this.columnDef.id;
const title = this.columnEditor && this.columnEditor.title || '';
const minValue = this.columnEditor.hasOwnProperty('minValue') ? this.columnEditor.minValue : DEFAULT_MIN_VALUE;
const maxValue = this.columnEditor.hasOwnProperty('maxValue') ? this.columnEditor.maxValue : DEFAULT_MAX_VALUE;
const defaultValue = this.editorParams.hasOwnProperty('sliderStartValue') ? this.editorParams.sliderStartValue : minValue;
Expand All @@ -190,6 +191,7 @@ export class SliderEditor implements Editor {
<div class="slider-editor editor-${columnId}">
<input type="range" id="${this._elementRangeInputId}"
name="${this._elementRangeInputId}"
title="${title}"
defaultValue="${defaultValue}" min="${minValue}" max="${maxValue}" step="${step}"
class="form-control slider-editor-input range" />
</div>`;
Expand All @@ -199,6 +201,7 @@ export class SliderEditor implements Editor {
<div class="input-group slider-editor editor-${columnId}">
<input type="range" id="${this._elementRangeInputId}"
name="${this._elementRangeInputId}"
title="${title}"
defaultValue="${defaultValue}" min="${minValue}" max="${maxValue}" step="${step}"
class="form-control slider-editor-input range" />
<div class="input-group-addon input-group-append slider-value"><span class="input-group-text" id="${this._elementRangeOutputId}">${defaultValue}</span></div>
Expand Down
3 changes: 2 additions & 1 deletion src/aurelia-slickgrid/editors/textEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,9 @@ export class TextEditor implements Editor {
init(): void {
const columnId = this.columnDef && this.columnDef.id;
const placeholder = this.columnEditor && this.columnEditor.placeholder || '';
const title = this.columnEditor && this.columnEditor.title || '';

this.$input = $(`<input type="text" class="editor-text editor-${columnId}" placeholder="${placeholder}" />`)
this.$input = $(`<input type="text" class="editor-text editor-${columnId}" placeholder="${placeholder}" title="${title}" />`)
.appendTo(this.args.container)
.on('keydown.nav', (event: JQueryEventObject) => {
this._lastInputEvent = event;
Expand Down
9 changes: 9 additions & 0 deletions src/aurelia-slickgrid/models/columnEditor.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,15 @@ export interface ColumnEditor {
*/
placeholder?: string;

/**
* Title attribute that can be used in some Editors as tooltip (usually the "input" editors).
*
* To use this as a Tooltip, Angular-Slickgrid doesn't (and will never) use any Angular 3rd party lib to display a real Tooltip,
* for that you can use any jQuery 3rd party lib like tipsy for example (we use it in our own project and it works)
* https://www.npmjs.com/package/jquery.tipsy
*/
title?: string;

/**
* Defaults to false, is the field required to be valid?
* Only on Editors that supports it.
Expand Down
1 change: 1 addition & 0 deletions src/examples/slickgrid/custom-inputEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export class CustomInputEditor implements Editor {

init(): void {
const placeholder = this.columnEditor && this.columnEditor.placeholder || '';
const title = this.columnEditor && this.columnEditor.title || '';

// this.$input = $(`<input type="text" class="editor-text" placeholder="${placeholder}" />`)
// .appendTo(this.args.container)
Expand Down
2 changes: 2 additions & 0 deletions src/examples/slickgrid/example3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,8 @@ export class Example3 {
type: FieldType.string,
editor: {
model: Editors.longText,
placeholder: 'something',
title: 'some title',
validator: myCustomTitleValidator, // use a custom validator
},
minWidth: 100,
Expand Down

0 comments on commit 6e0d125

Please sign in to comment.