Move FormModel to components/ui/form. Fixed el typechecking in ref callback

This commit is contained in:
SleepWalker 2016-05-02 12:38:45 +03:00
parent 82416f788f
commit e1f16d7346
7 changed files with 14 additions and 14 deletions

View File

@ -5,7 +5,7 @@ import React, { Component, PropTypes } from 'react';
import AuthError from 'components/auth/authError/AuthError';
import { userShape } from 'components/user/User';
import Form from 'models/Form';
import { FormModel } from 'components/ui/form';
export default class BaseAuthBody extends Component {
static contextTypes = {
@ -32,7 +32,7 @@ export default class BaseAuthBody extends Component {
onClearErrors = this.context.clearErrors;
form = new Form();
form = new FormModel();
bindField = this.form.bindField.bind(this.form);
serialize = this.form.serialize.bind(this.form);

View File

@ -4,8 +4,7 @@ import { FormattedMessage as Message } from 'react-intl';
import { Link } from 'react-router';
import Helmet from 'react-helmet';
import { Input, Button, Checkbox, Form } from 'components/ui/form';
import FormModel from 'models/Form';
import { Input, Button, Checkbox, Form, FormModel } from 'components/ui/form';
import styles from 'components/profile/profileForm.scss';
import messages from './ChangePassword.messages';
@ -14,7 +13,7 @@ export default class ChangePassword extends Component {
static displayName = 'ChangePassword';
static propTypes = {
form: PropTypes.instanceOf(FormModel).isRequired,
form: PropTypes.instanceOf(FormModel),
onSubmit: PropTypes.func.isRequired
};

View File

@ -2,8 +2,7 @@ import React, { Component, PropTypes } from 'react';
import { FormattedMessage as Message } from 'react-intl';
import FormModel from 'models/Form';
import { Form, Button, Input } from 'components/ui/form';
import { Form, Button, Input, FormModel } from 'components/ui/form';
import messages from './PasswordRequestForm.messages';

View File

@ -2,7 +2,7 @@ import React, { Component, PropTypes } from 'react';
import classNames from 'classnames';
import FormModel from 'models/Form';
import FormModel from './FormModel';
import styles from './form.scss';

View File

@ -1,6 +1,6 @@
import FormInputComponent from 'components/ui/form/FormInputComponent';
import FormInputComponent from './FormInputComponent';
export default class Form {
export default class FormModel {
fields = {};
errors = {};
@ -18,8 +18,8 @@ export default class Form {
const props = {
name,
ref: (el) => {
if (!(el instanceof FormInputComponent)) {
throw new Error('Expected a component from components/ui/form module');
if (el && !(el instanceof FormInputComponent)) {
throw new Error('Expected FormInputComponent component');
}
this.fields[name] = el;

View File

@ -2,10 +2,12 @@ import Input from './Input';
import Checkbox from './Checkbox';
import Button from './Button';
import Form from './Form';
import FormModel from './FormModel';
export {
Input,
Button,
Checkbox,
Form
Form,
FormModel
};

View File

@ -1,7 +1,7 @@
import React, { Component, PropTypes } from 'react';
import accounts from 'services/api/accounts';
import FormModel from 'models/Form';
import { FormModel } from 'components/ui/form';
import ChangePassword from 'components/profile/changePassword/ChangePassword';
import PasswordRequestForm from 'components/profile/passwordRequestForm/PasswordRequestForm';