Skip to content

Commit

Permalink
onBlurValidateAgainstList() para #30
Browse files Browse the repository at this point in the history
  • Loading branch information
diegoefe committed Dec 5, 2016
1 parent 112e20d commit 4798441
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 5 deletions.
17 changes: 16 additions & 1 deletion src/txt-to-sql.jade
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,17 @@ html(lang=lang)
html.td([createInput(name, type, value, width, id || name)])
]).create();
}
function onBlurValidateAgainstList(element, list) {
element.addEventListener('blur', function(event) {
var buttonGenerate = getID('generate');
buttonGenerate.disabled = list.indexOf(element.value)===-1;
if(buttonGenerate.disabled) {
errMessage.textContent = element.value+' not found in '+JSON.stringify(list);
} else {
errMessage.textContent = '';
}
}, false);
}
function createList(label, name, value, alternatives, width) {
var valuesID=name+'_values';
var options=alternatives.map(function(item) {
Expand Down Expand Up @@ -311,7 +322,7 @@ html(lang=lang)
}).then(function(prepared) {
if(prepared.errors) { throw new Error(prepared.errors.join('\n')); }
preparedColumns = prepared.columns;
var butGenerate = html.input({type:'button', value:messages.generate}).create();
var butGenerate = html.input({type:'button', value:messages.generate, id:'generate'}).create();
butGenerate.file = file;
butGenerate.addEventListener('click', handleGenerate, false);
var includePrimaryKeyValue = prepared.opts.includePrimaryKey !== null ?
Expand Down Expand Up @@ -362,6 +373,10 @@ html(lang=lang)
html.td([tblFields])
]),
]).create()]);
onBlurValidateAgainstList(getID('columnNamesFormat'), txtToSql.validFormats);
onBlurValidateAgainstList(getID('outputEngine'), txtToSql.validEngines);
onBlurValidateAgainstList(getID('inputEncoding'), txtToSql.validEncodings);
onBlurValidateAgainstList(getID('outputEncoding'), txtToSql.validEncodings);
errMessage.textContent=""; // if all goes ok, clear' em
log.textContent=messages.loaded+' '+file.name;
delete getID('inputFile').files;
Expand Down
6 changes: 3 additions & 3 deletions src/txt-to-sql.styl
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ table.inner
width:1%;
white-space:nowrap;
}

input
width auto

input[type="file"]
width 400px
width 400px
17 changes: 16 additions & 1 deletion web/txt-to-sql.html
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,17 @@
html.td([createInput(name, type, value, width, id || name)])
]).create();
}
function onBlurValidateAgainstList(element, list) {
element.addEventListener('blur', function(event) {
var buttonGenerate = getID('generate');
buttonGenerate.disabled = list.indexOf(element.value)===-1;
if(buttonGenerate.disabled) {
errMessage.textContent = element.value+' not found in '+JSON.stringify(list);
} else {
errMessage.textContent = '';
}
}, false);
}
function createList(label, name, value, alternatives, width) {
var valuesID=name+'_values';
var options=alternatives.map(function(item) {
Expand Down Expand Up @@ -260,7 +271,7 @@
}).then(function(prepared) {
if(prepared.errors) { throw new Error(prepared.errors.join('\n')); }
preparedColumns = prepared.columns;
var butGenerate = html.input({type:'button', value:messages.generate}).create();
var butGenerate = html.input({type:'button', value:messages.generate, id:'generate'}).create();
butGenerate.file = file;
butGenerate.addEventListener('click', handleGenerate, false);
var includePrimaryKeyValue = prepared.opts.includePrimaryKey !== null ?
Expand Down Expand Up @@ -311,6 +322,10 @@
html.td([tblFields])
]),
]).create()]);
onBlurValidateAgainstList(getID('columnNamesFormat'), txtToSql.validFormats);
onBlurValidateAgainstList(getID('outputEngine'), txtToSql.validEngines);
onBlurValidateAgainstList(getID('inputEncoding'), txtToSql.validEncodings);
onBlurValidateAgainstList(getID('outputEncoding'), txtToSql.validEncodings);
errMessage.textContent=""; // if all goes ok, clear' em
log.textContent=messages.loaded+' '+file.name;
delete getID('inputFile').files;
Expand Down

0 comments on commit 4798441

Please sign in to comment.