Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Fields default to Blank String #1126

Merged
merged 11 commits into from
Mar 28, 2018
2 changes: 1 addition & 1 deletion src/actions/entries.js
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ export function createEmptyDraft(collection) {
return (dispatch) => {
const dataFields = {};
collection.get('fields', List()).forEach((field) => {
dataFields[field.get('name')] = field.get('default', null);
dataFields[field.get('name')] = undefined;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MichaelRomani We still want to allow users to manually set a default here, just default it to undefined instead of null. The code would be field.get('default'), just removing null as the second param like @erquhart mentioned.

});
const newEntry = createEntry(collection.get('name'), '', '', { data: dataFields });
dispatch(emptyDraftCreated(newEntry));
Expand Down
4 changes: 4 additions & 0 deletions src/components/EditorWidgets/Boolean/BooleanControl.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,7 @@ BooleanControl.propTypes = {
forID: PropTypes.string,
value: PropTypes.bool,
};

BooleanControl.defaultProps = {
value: false,
};
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ export default class MarkdownControl extends React.Component {
value: PropTypes.string,
};

static defaultProps = {
value: '',
};

constructor(props) {
super(props);
editorControl = props.editorControl;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,8 @@ MarkdownPreview.propTypes = {
value: PropTypes.string,
};

MarkdownPreview.defaultProps = {
value: '',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason we need to set this on the MD preview, and not any of the other previews?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you referring to the 'RawEditor' and 'VisualEditor' files?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as the kitchen sink goes, I'll take a look this evening or tomorrow afternoon. My apologies, I did not test creating a new sink.

Copy link
Contributor

@tech4him1 tech4him1 Feb 27, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, I just noticed that you set a default value on the MarkdownPreview as well as the MarkdownControl. Was there a reason?

};

export default MarkdownPreview;
4 changes: 4 additions & 0 deletions src/components/EditorWidgets/Number/NumberControl.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ export default class NumberControl extends React.Component {
max: PropTypes.number,
};

static defaultProps = {
value: '',
};

handleChange = (e) => {
const valueType = this.props.field.get('valueType');
const { onChange } = this.props;
Expand Down
4 changes: 4 additions & 0 deletions src/components/EditorWidgets/Object/ObjectControl.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ export default class ObjectControl extends Component {
forList: PropTypes.bool,
};

static defaultProps = {
value: {},
};

constructor(props) {
super(props);
this.state = {
Expand Down
4 changes: 4 additions & 0 deletions src/components/EditorWidgets/Relation/RelationControl.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ class RelationControl extends Component {
setInactiveStyle: PropTypes.func.isRequired,
};

static defaultProps = {
value: '',
};

constructor(props, ctx) {
super(props, ctx);
this.controlID = uuid();
Expand Down
4 changes: 4 additions & 0 deletions src/components/EditorWidgets/Select/SelectControl.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ export default class SelectControl extends React.Component {
}),
};

static defaultProps = {
value: '',
};

handleChange = (e) => {
this.props.onChange(e.target.value);
};
Expand Down
4 changes: 4 additions & 0 deletions src/components/EditorWidgets/String/StringControl.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ export default class StringControl extends React.Component {
setInactiveStyle: PropTypes.func.isRequired,
};

static defaultProps = {
value: '',
};

render() {
const {
forID,
Expand Down
4 changes: 4 additions & 0 deletions src/components/EditorWidgets/Text/TextControl.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ export default class TextControl extends React.Component {
setInactiveStyle: PropTypes.func.isRequired,
};

static defaultProps = {
value: '',
};

/**
* Always update to ensure `react-textarea-autosize` properly calculates
* height. Certain situations, such as this widget being nested in a list
Expand Down
4 changes: 4 additions & 0 deletions src/components/EditorWidgets/withMedia/withMediaControl.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ export default function withMediaControl(forImage) {
value: PropTypes.node,
};

static defaultProps = {
value: '',
};

constructor(props) {
super(props);
this.controlID = uuid();
Expand Down