Skip to content

Commit 3f274ca

Browse files
committed
Updated samples.
1 parent 3ea7e9f commit 3f274ca

40 files changed

Lines changed: 204 additions & 171 deletions

samples/react/00 SimpleForm/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"license": "ISC",
1010
"dependencies": {
1111
"bootstrap": "^3.3.7",
12+
"core-js": "^2.4.1",
1213
"jquery": "^3.2.0",
1314
"lc-form-validation": "file:../../../lib/",
1415
"react": "^15.4.2",

samples/react/00 SimpleForm/src/actions/customerSaveCompleted.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ interface ICustomerSaveCompletedAction {
66
formValidationResult: FormValidationResult;
77
}
88

9-
let customerSaveCompleted = (formValidationResult: FormValidationResult): ICustomerSaveCompletedAction => {
9+
const customerSaveCompleted = (formValidationResult: FormValidationResult): ICustomerSaveCompletedAction => {
1010
return {
1111
type: actionsDef.customer.CUSTOMER_SAVE_COMPLETED,
1212
formValidationResult

samples/react/00 SimpleForm/src/actions/customerSaveStart.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@ import { customerFormValidation } from '../components/sampleForm/validations/cus
66
export function customerSaveStart(viewModel: any) {
77

88
return (dispatcher) => {
9-
109
customerFormValidation.validateForm(viewModel).then(
11-
function (formValidationResult: FormValidationResult) {
10+
(formValidationResult: FormValidationResult) => {
1211
if (formValidationResult.succeeded) {
1312
// Call here the async call to save
1413
// additional logic or actins to be added on a real case

samples/react/00 SimpleForm/src/actions/customerUIInputStart.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export function customerUIInputStart(viewModel: any, fieldName: string, value: a
77

88
return (dispatcher) => {
99
customerFormValidation.validateField(viewModel, fieldName, value).then(
10-
function (fieldValidationResult: FieldValidationResult) {
10+
(fieldValidationResult: FieldValidationResult) => {
1111
dispatcher(customerUIInputCompleted(fieldName, value, fieldValidationResult));
1212
}
1313
);

samples/react/00 SimpleForm/src/actions/customerUInputCompleted.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ interface ICustomerUIInputCompletedAction {
88
fieldValidationResult: FieldValidationResult;
99
}
1010

11-
let customerUIInputCompleted = (fieldName: string, value: any, fieldValidationResult: FieldValidationResult): ICustomerUIInputCompletedAction => {
12-
11+
const customerUIInputCompleted = (fieldName: string, value: any, fieldValidationResult: FieldValidationResult): ICustomerUIInputCompletedAction => {
1312
return {
1413
type: actionsDef.customer.CUSTOMER_PROCESS_UI_INPUT_COMPLETED,
1514
fieldName,

samples/react/00 SimpleForm/src/components/app.tsx

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,13 @@ import { Provider } from 'react-redux';
55
import reducers from '../reducers'
66
import { ContainerSampleForm } from './sampleForm/sampleForm.container';
77

8-
let store = createStore(
9-
reducers
10-
, applyMiddleware(ReduxThunk)
8+
const store = createStore(
9+
reducers,
10+
applyMiddleware(ReduxThunk)
1111
);
1212

13-
14-
interface Props extends React.Props<App> {
15-
}
16-
17-
export default class App extends React.Component<Props, {}> {
18-
public render() {
13+
export default class App extends React.Component<{}, {}> {
14+
render() {
1915
return (
2016
<Provider store={store}>
2117
<div className="container-fluid">

samples/react/00 SimpleForm/src/components/common/input.tsx

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,18 @@ interface Props {
1010
}
1111

1212
export class Input extends React.Component<Props, {}> {
13-
constructor(props: Props) {
14-
super(props);
15-
}
16-
17-
public render() {
18-
var wrapperClass: string = 'form-group';
13+
render() {
14+
let wrapperClass = 'form-group';
1915
if (this.props.error && this.props.error.length > 0) {
20-
wrapperClass += " " + 'has-error';
16+
wrapperClass = '${wrapperClass} has-error';
2117
}
18+
2219
return (
2320
<div className={wrapperClass}>
2421
<label htmlFor={this.props.name}>{this.props.label}</label>
2522
<div className="field">
2623
<input type="text"
24+
id={this.props.name}
2725
name={this.props.name}
2826
className="form-control"
2927
placeholder={this.props.placeholder}

samples/react/00 SimpleForm/src/components/sampleForm/sampleForm.tsx

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,27 @@ interface Props extends React.Props<SampleForm> {
1111
}
1212

1313
export class SampleForm extends React.Component<Props, {}> {
14+
15+
constructor(props) {
16+
super(props);
17+
18+
this.onSave = this.onSave.bind(this);
19+
this.updateMemberFromUI = this.updateMemberFromUI.bind(this);
20+
}
21+
1422
private updateMemberFromUI(event) {
15-
var field = event.target.name;
16-
var value = event.target.value;
23+
const field = event.target.name;
24+
const value = event.target.value;
1725

1826
this.props.fireValidationFieldValueChanged(this.props.customer, field, value);
1927
}
2028

21-
private OnSave(event) {
29+
private onSave(event) {
2230
event.preventDefault();
2331
this.props.saveCustomer(this.props.customer);
2432
}
2533

26-
public render() {
34+
render() {
2735
return (
2836
<form>
2937
<h1>Customer Form</h1>
@@ -32,18 +40,18 @@ export class SampleForm extends React.Component<Props, {}> {
3240
name="fullname"
3341
label="full name"
3442
value={this.props.customer.fullname}
35-
onChange={this.updateMemberFromUI.bind(this)}
43+
onChange={this.updateMemberFromUI}
3644
error={(!this.props.errors.fullname) ? '' : this.props.errors.fullname.errorMessage} />
3745

3846
<Input
3947
name="password"
4048
label="password"
4149
value={this.props.customer.password}
42-
onChange={this.updateMemberFromUI.bind(this)}
50+
onChange={this.updateMemberFromUI}
4351
error={(!this.props.errors.password) ? '' : this.props.errors.password.errorMessage} />
4452

4553
<input type="submit" value="Save" className="btn btn-default"
46-
onClick={this.OnSave.bind(this)} />
54+
onClick={this.onSave} />
4755
</form>
4856
);
4957
}

samples/react/00 SimpleForm/src/index.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@ import * as ReactDOM from 'react-dom';
33
import App from './components/app';
44

55
ReactDOM.render(
6-
<App />
7-
, document.getElementById('root'));
6+
<App />,
7+
document.getElementById('root'),
8+
);

samples/react/00 SimpleForm/src/reducers/customer.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ export class CustomerState {
1010
customer: CustomerEntity;
1111
customerErrors: CustomerErrors;
1212

13-
public constructor() {
13+
constructor() {
1414
this.customer = new CustomerEntity();
1515
this.customerErrors = new CustomerErrors();
1616
}
1717
}
1818

19-
export let customerReducer = (state: CustomerState = new CustomerState(), action): CustomerState => {
19+
export const customerReducer = (state: CustomerState = new CustomerState(), action): CustomerState => {
2020
switch (action.type) {
2121
case actionsDef.customer.CUSTOMER_PROCESS_UI_INPUT_COMPLETED:
2222
return customerProcessUIInputCompleted(state, action);
@@ -30,11 +30,11 @@ export let customerReducer = (state: CustomerState = new CustomerState(), action
3030
}
3131

3232
function customerProcessUIInputCompleted(state: CustomerState, action: ICustomerUIInputCompletedAction): CustomerState {
33-
let newCustomer: CustomerEntity = Object.assign({}, state.customer, {
33+
const newCustomer: CustomerEntity = Object.assign({}, state.customer, {
3434
[action.fieldName]: action.value
3535
});
3636

37-
let newCustomerErrors: CustomerErrors = Object.assign({}, state.customerErrors, {
37+
const newCustomerErrors: CustomerErrors = Object.assign({}, state.customerErrors, {
3838
[action.fieldName]: action.fieldValidationResult
3939
});
4040

@@ -45,7 +45,7 @@ function customerProcessUIInputCompleted(state: CustomerState, action: ICustomer
4545
}
4646

4747
function customerSaveCompleted(state: CustomerState, action: ICustomerSaveCompletedAction): CustomerState {
48-
let newCustomerErrors: CustomerErrors = Object.assign({}, state.customerErrors);
48+
const newCustomerErrors: CustomerErrors = Object.assign({}, state.customerErrors);
4949

5050
action.formValidationResult.fieldErrors.forEach(fieldValidationResult => {
5151
newCustomerErrors[fieldValidationResult.key] = fieldValidationResult;

0 commit comments

Comments
 (0)