@gpa-gemstone/react-forms 1.1.32 → 1.1.34
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/Input.d.ts +3 -2
- package/lib/Input.js +9 -3
- package/lib/Select.js +23 -8
- package/lib/TextArea.js +3 -1
- package/package.json +1 -1
package/lib/Input.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
import * as React from 'react';
|
|
2
2
|
interface IProps<T> {
|
|
3
3
|
Record: T;
|
|
4
4
|
Field: keyof T;
|
|
@@ -7,8 +7,9 @@ interface IProps<T> {
|
|
|
7
7
|
Label?: string;
|
|
8
8
|
Feedback?: string;
|
|
9
9
|
Disabled?: boolean;
|
|
10
|
-
Type?: 'number' | 'text' | 'password' | 'email' | 'color';
|
|
10
|
+
Type?: 'number' | 'text' | 'password' | 'email' | 'color' | 'integer';
|
|
11
11
|
Help?: string | JSX.Element;
|
|
12
|
+
Style?: React.CSSProperties;
|
|
12
13
|
}
|
|
13
14
|
export default function Input<T>(props: IProps<T>): JSX.Element;
|
|
14
15
|
export {};
|
package/lib/Input.js
CHANGED
|
@@ -53,7 +53,7 @@ function Input(props) {
|
|
|
53
53
|
setInternal(false);
|
|
54
54
|
}, [props.Record[props.Field]]);
|
|
55
55
|
function valueChange(value) {
|
|
56
|
-
var _a, _b;
|
|
56
|
+
var _a, _b, _c;
|
|
57
57
|
setInternal(true);
|
|
58
58
|
if (props.Type === 'number') {
|
|
59
59
|
if ((0, helper_functions_1.IsNumber)(value)) {
|
|
@@ -61,12 +61,18 @@ function Input(props) {
|
|
|
61
61
|
setHeldVal(value);
|
|
62
62
|
}
|
|
63
63
|
}
|
|
64
|
+
else if (props.Type === 'integer') {
|
|
65
|
+
if ((0, helper_functions_1.IsInteger)(value)) {
|
|
66
|
+
props.Setter(__assign(__assign({}, props.Record), (_b = {}, _b[props.Field] = value !== '' ? parseFloat(value) : null, _b)));
|
|
67
|
+
setHeldVal(value);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
64
70
|
else {
|
|
65
|
-
props.Setter(__assign(__assign({}, props.Record), (
|
|
71
|
+
props.Setter(__assign(__assign({}, props.Record), (_c = {}, _c[props.Field] = value !== '' ? value : null, _c)));
|
|
66
72
|
setHeldVal(value);
|
|
67
73
|
}
|
|
68
74
|
}
|
|
69
|
-
return (React.createElement("div", { className: "form-group" },
|
|
75
|
+
return (React.createElement("div", { className: "form-group", style: props.Style },
|
|
70
76
|
(props.Label !== "") ?
|
|
71
77
|
React.createElement("label", null,
|
|
72
78
|
props.Label === undefined ? props.Field : props.Label,
|
package/lib/Select.js
CHANGED
|
@@ -44,6 +44,28 @@ function Select(props) {
|
|
|
44
44
|
React.useEffect(function () {
|
|
45
45
|
setGuid((0, helper_functions_1.CreateGuid)());
|
|
46
46
|
}, []);
|
|
47
|
+
React.useEffect(function () {
|
|
48
|
+
var _a;
|
|
49
|
+
var currentValue = GetRecordValue();
|
|
50
|
+
if (!((_a = props.EmptyOption) !== null && _a !== void 0 ? _a : false) && props.Options.length > 0 && props.Options.findIndex(function (option) { return option.Value === currentValue; }) === -1) {
|
|
51
|
+
SetRecord(props.Options[0].Value);
|
|
52
|
+
// tslint:disable-next-line
|
|
53
|
+
console.warn("The current value is not available as an option. Specify EmptyOption=true if the value should be allowed.");
|
|
54
|
+
}
|
|
55
|
+
}, [props.Options]);
|
|
56
|
+
function SetRecord(value) {
|
|
57
|
+
var record = __assign({}, props.Record);
|
|
58
|
+
if (value !== '')
|
|
59
|
+
record[props.Field] = value;
|
|
60
|
+
else
|
|
61
|
+
record[props.Field] = null;
|
|
62
|
+
props.Setter(record);
|
|
63
|
+
}
|
|
64
|
+
;
|
|
65
|
+
function GetRecordValue() {
|
|
66
|
+
return props.Record[props.Field] == null ? '' : props.Record[props.Field].toString();
|
|
67
|
+
}
|
|
68
|
+
;
|
|
47
69
|
return (React.createElement("div", { className: "form-group" },
|
|
48
70
|
(props.Label !== "") ?
|
|
49
71
|
React.createElement("label", null,
|
|
@@ -52,14 +74,7 @@ function Select(props) {
|
|
|
52
74
|
props.Help !== undefined ?
|
|
53
75
|
React.createElement(HelperMessage_1.default, { Show: showHelp, Target: guid }, props.Help)
|
|
54
76
|
: null,
|
|
55
|
-
React.createElement("select", { "data-help": guid, className: "form-control", onChange: function (evt) {
|
|
56
|
-
var record = __assign({}, props.Record);
|
|
57
|
-
if (evt.target.value !== '')
|
|
58
|
-
record[props.Field] = evt.target.value;
|
|
59
|
-
else
|
|
60
|
-
record[props.Field] = null;
|
|
61
|
-
props.Setter(record);
|
|
62
|
-
}, value: props.Record[props.Field] == null ? '' : props.Record[props.Field].toString(), disabled: props.Disabled == null ? false : props.Disabled },
|
|
77
|
+
React.createElement("select", { "data-help": guid, className: "form-control", onChange: function (evt) { return SetRecord(evt.target.value); }, value: GetRecordValue(), disabled: props.Disabled == null ? false : props.Disabled },
|
|
63
78
|
props.EmptyOption ? React.createElement("option", { value: "" }, props.EmptyLabel !== undefined ? props.EmptyLabel : '') : null,
|
|
64
79
|
props.Options.map(function (a, i) { return (React.createElement("option", { key: i, value: a.Value }, a.Label)); }))));
|
|
65
80
|
}
|
package/lib/TextArea.js
CHANGED
|
@@ -36,7 +36,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
36
36
|
var React = require("react");
|
|
37
37
|
function TextArea(props) {
|
|
38
38
|
return (React.createElement("div", { className: "form-group" },
|
|
39
|
-
|
|
39
|
+
(props.Label !== "") ? React.createElement("label", null,
|
|
40
|
+
props.Label === undefined ? props.Field : props.Label,
|
|
41
|
+
" ") : null,
|
|
40
42
|
React.createElement("textarea", { rows: props.Rows, className: props.Valid(props.Field) ? 'form-control' : 'form-control is-invalid', onChange: function (evt) {
|
|
41
43
|
var record = __assign({}, props.Record);
|
|
42
44
|
if (evt.target.value !== '')
|