Skip to content

false-boolean-option-fix| checking for undefined and null for value (#1) #124

New issue

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

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

Already on GitHub? # to your account

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
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
224 changes: 112 additions & 112 deletions dist/css/brutusin-json-forms.css
Original file line number Diff line number Diff line change
@@ -1,112 +1,112 @@
/*
* Copyright 2015 brutusin.org
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* @author Ignacio del Valle Alles idelvall@brutusin.org
*/
.add-pattern-div{
margin-top: 6px;
}
.loading-layer{
position: absolute;
top:0px;
left:0px;
z-index : 10;
width: 100%;
height: 100%;
opacity: 0.7;
background-color: white;
}
.loading-icon{
position: absolute;
top:14px;
left:50%;
z-index : 11;
}
.loading-icon-select{
position: absolute;
top:14px;
left:50%;
z-index : 11;
}
.loading-icon-checkbox{
position: absolute;
top:7px;
left:3px;
z-index : 11;
}
.glyphicon-refresh-animate {
animation: spin .7s infinite linear;
-webkit-animation: spin2 .7s infinite linear;
}
@-webkit-keyframes spin2 {
from { -webkit-transform: rotate(0deg);}
to { -webkit-transform: rotate(360deg);}
}
@keyframes spin {
from { transform: scale(1) rotate(0deg);}
to { transform: scale(1) rotate(360deg);}
}
form.brutusin-form table, form.brutusin-form input, form.brutusin-form select, form.brutusin-form textarea{
width: 100% !important;
min-width: 80px;
}
form.brutusin-form input[type=checkbox]{
width: auto !important;
min-width: auto !important;
}
form.brutusin-form textarea{
height: 8em;
}
form.brutusin-form table table{
border-left: solid 1px;
border-color: lightgray;
margin: 4px;
}
form.brutusin-form td {
vertical-align: top;
padding: 4px;
white-space: nowrap;
}
form.brutusin-form td.prop-name {
text-align: right;
}
form.brutusin-form td.add-prop-name table {
text-align: right;
border: none;
}
form.brutusin-form td.add-prop-name table td {
vertical-align: middle;
}
form.brutusin-form td.prop-value {
width: 100%;
text-align: left;
}
form.brutusin-form td.item-index{
font-size: 0.8em;
color: lightgray;
width: 25px;
text-align: right;
}
form.brutusin-form td.item-action{
width: 30px;
}
form.brutusin-form .error {
border-color: red;
}
form.brutusin-form .error-message {
color: red;
}
/*
* Copyright 2015 brutusin.org
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* @author Ignacio del Valle Alles idelvall@brutusin.org
*/
.add-pattern-div{
margin-top: 6px;
}
.loading-layer{
position: absolute;
top:0px;
left:0px;
z-index : 10;
width: 100%;
height: 100%;
opacity: 0.7;
background-color: white;
}
.loading-icon{
position: absolute;
top:14px;
left:50%;
z-index : 11;
}
.loading-icon-select{
position: absolute;
top:14px;
left:50%;
z-index : 11;
}
.loading-icon-checkbox{
position: absolute;
top:7px;
left:3px;
z-index : 11;
}
.glyphicon-refresh-animate {
animation: spin .7s infinite linear;
-webkit-animation: spin2 .7s infinite linear;
}

@-webkit-keyframes spin2 {
from { -webkit-transform: rotate(0deg);}
to { -webkit-transform: rotate(360deg);}
}

@keyframes spin {
from { transform: scale(1) rotate(0deg);}
to { transform: scale(1) rotate(360deg);}
}
form.brutusin-form table, form.brutusin-form input, form.brutusin-form select, form.brutusin-form textarea{
width: 100% !important;
min-width: 80px;
}
form.brutusin-form input[type=checkbox]{
width: auto !important;
min-width: auto !important;
}
form.brutusin-form textarea{
height: 8em;
}
form.brutusin-form table table{
border-left: solid 1px;
border-color: lightgray;
margin: 4px;
}
form.brutusin-form td {
vertical-align: top;
padding: 4px;
white-space: nowrap;
}
form.brutusin-form td.prop-name {
text-align: right;
}
form.brutusin-form td.add-prop-name table {
text-align: right;
border: none;
}
form.brutusin-form td.add-prop-name table td {
vertical-align: middle;
}
form.brutusin-form td.prop-value {
width: 100%;
text-align: left;
}
form.brutusin-form td.item-index{
font-size: 0.8em;
color: lightgray;
width: 25px;
text-align: right;
}
form.brutusin-form td.item-action{
width: 30px;
}
form.brutusin-form .error {
border-color: red;
}
form.brutusin-form .error-message {
color: red;
}
32 changes: 23 additions & 9 deletions dist/js/brutusin-json-forms.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,6 @@ if (typeof brutusin === "undefined") {
} else if (s.media) {
input = document.createElement("input");
input.type = "file";
appendChild(input, option, s);
// XXX TODO, encode the SOB properly.
} else if (s.enum) {
input = document.createElement("select");
Expand Down Expand Up @@ -205,7 +204,7 @@ if (typeof brutusin === "undefined") {
}
}
if (s.enum.length === 1)
input.selectedIndex = 1;
input.selectedIndex = 0;
else
input.selectedIndex = selectedIndex;
} else {
Expand All @@ -223,6 +222,10 @@ if (typeof brutusin === "undefined") {
// #46, problem in IE11. TODO polyfill?
input.type = "text";
}
} else if (s.format === "date") {
input.type = "date";
} else if (s.format === "time") {
input.type = "time";
} else if (s.format === "email") {
input.type = "email";
} else if (s.format === "text") {
Expand Down Expand Up @@ -345,8 +348,8 @@ if (typeof brutusin === "undefined") {
if (s.required) {
input = document.createElement("input");
input.type = "checkbox";
if (value === true) {
input.checked = true;
if (value === true || value !== false && s.default) {
input.checked = true;
}
} else {
input = document.createElement("select");
Expand Down Expand Up @@ -747,6 +750,7 @@ if (typeof brutusin === "undefined") {
if (s.readOnly)
addButton.disabled = true;
addButton.setAttribute('type', 'button');
addButton.className = "addItem";
addButton.getValidationError = function () {
if (s.minItems && s.minItems > table.rows.length) {
return BrutusinForms.messages["minItems"].format(s.minItems);
Expand Down Expand Up @@ -827,8 +831,8 @@ if (typeof brutusin === "undefined") {

obj.getData = function () {
function removeEmptiesAndNulls(object, s) {
if (ss === null) {
ss = SCHEMA_ANY;
if (s === null) {
s = SCHEMA_ANY;
}
if (s.$ref) {
s = getDefinition(s.$ref);
Expand All @@ -844,7 +848,7 @@ if (typeof brutusin === "undefined") {
return clone;
} else if (object === "") {
return null;
} else if (object instanceof Object) {
} else if (object instanceof Object && !(object instanceof File)) {
var clone = new Object();
var nonEmpty = false;
for (var prop in object) {
Expand Down Expand Up @@ -1193,7 +1197,7 @@ if (typeof brutusin === "undefined") {
} else if (propertyProvider) {
renderTitle(titleContainer, propertyProvider.getValue(), s);
}
if (!value) {
if (typeof value === "undefined" || value === null) {
if (typeof initialValue !== "undefined" && initialValue !== null) {
value = getInitialValue(id);
} else {
Expand Down Expand Up @@ -1247,6 +1251,16 @@ if (typeof brutusin === "undefined") {
}

function getValue(schema, input) {
if(schema.$id === "$.Document") {
input.type = 'file';
input.getValue = function(){
if(input.value && input.files.length ){
return input.files[0];
} else {
return null;
}
};
}
if (typeof input.getValue === "function") {
return input.getValue();
}
Expand Down Expand Up @@ -1307,7 +1321,7 @@ if (typeof brutusin === "undefined") {

function cleanSchemaMap(schemaId) {
for (var prop in schemaMap) {
if (schemaId.startsWith(prop)) {
if (prop.startsWith(schemaId)) {
delete schemaMap[prop];
}
}
Expand Down
Loading