2
0
mirror of https://github.com/frappe/books.git synced 2024-11-10 07:40:55 +00:00

Merge pull request #42 from netchampfaris/controls

Controls
This commit is contained in:
Faris Ansari 2018-04-04 16:03:00 +05:30 committed by GitHub
commit ee5bf756a9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 35 additions and 5 deletions

View File

@ -418,3 +418,7 @@ input[type=file] {
position: absolute;
z-index: -1;
}
.was-validated input[type=file]:invalid + button {
border-color: $red;
}

View File

@ -86,6 +86,18 @@ module.exports = {
}
},
toggleClass(element, className, flag) {
if (flag === undefined) {
flag = !element.classList.contains(className);
}
if (!flag) {
this.removeClass(element, className);
} else {
this.addClass(element, className);
}
},
toggle(element, default_display = '') {
element.style.display = element.style.display === 'none' ? default_display : 'none';
},

View File

@ -8,18 +8,26 @@ class AutocompleteControl extends BaseControl {
this.setupAwesomplete();
}
setupAwesomplete() {
async setupAwesomplete() {
this.awesomplete = new Awesomplete(this.input, {
minChars: 0,
maxItems: 99
});
this.list = await this.getList();
// rebuild the list on input
this.input.addEventListener('input', async (event) => {
let list = await this.getList();
this.awesomplete.list = list;
this.input.addEventListener('input', (event) => {
this.awesomplete.list = this.list;
});
}
validate(value) {
if (this.list.includes(value)) {
return value;
}
return false;
}
};
module.exports = AutocompleteControl;

View File

@ -169,6 +169,7 @@ class BaseControl {
async handleChange(event) {
let value = await this.parse(this.getInputValue());
value = await this.validate(value);
this.input.setCustomValidity(value === false ? 'error' : '');
await this.updateDocValue(value);
}

View File

@ -3,7 +3,11 @@ const BaseControl = require('./base');
class DataControl extends BaseControl {
make() {
super.make();
this.input.setAttribute('type', 'text');
if (!this.inputType) {
this.inputType = 'text';
}
this.input.setAttribute('type', this.inputType);
}
};

View File

@ -7,6 +7,7 @@ class FileControl extends BaseControl {
this.fileButton = frappe.ui.create('button', {
className: 'btn btn-outline-secondary btn-block',
inside: this.getInputParent(),
type: 'button',
textContent: 'Choose a file...',
onclick: () => {
this.input.click();