Commit 3b11b824 authored by Florent Chehab's avatar Florent Chehab

Added serialize from field method

parent 1946dbe9
......@@ -28,7 +28,7 @@ class LocalizedUtils extends DateFnsUtils {
class DateField extends Field {
getValue() {
serializeFromField() {
return dateToDateStr(this.state.value);
}
......
......@@ -4,6 +4,13 @@ import PropTypes from "prop-types";
import Form from "../Form";
import FieldWrapper from "./FieldWrapper";
/**
* Class that handle fields logic
*
* @abstract
* @class Field
* @extends {PureComponent}
*/
class Field extends PureComponent {
// Attribute that will be used to replace null value
......@@ -12,8 +19,7 @@ class Field extends PureComponent {
/**
*Creates an instance of Field.
* @param {object} props
* @param {any} customDefaultValue use this parameter when a defaultNullValue needs to be set dynamically, otherwise, use class attribute defaultNullValue
* @param {*} [customStateAttrs={}] add custom state attributes on creation
* @param {object} [customStateAttrs={}] add custom state attributes on creation
* @memberof Field
*/
constructor(props, customStateAttrs = {}) {
......@@ -23,7 +29,6 @@ class Field extends PureComponent {
props.form.fieldSubscribe(props.fieldMapping, this);
let { value } = props;
this.state = {
value: value,
...customStateAttrs,
......@@ -46,14 +51,31 @@ class Field extends PureComponent {
return { status: messages.length > 0, messages };
}
getValue() {
// function to get the value, ready to send to server
// You might need to override this for weird formats such as dates.
/**
* function to get serialize the value from the field, to get it ready to send to server
* You might need to override this for weird formats such as dates.
*
* @returns
* @memberof Field
*/
serializeFromField(){
return this.state.value;
}
/**
* TODO
* Returns the serialized value of the field
*
* @returns
* @memberof Field
*/
getValue() {
return this.serializeFromField();
}
/**
* Function that should render the field itself
*
* MUST BE OVERRIDE
*
* @memberof Field
*/
......
......@@ -61,7 +61,8 @@ class UsefulLinksField extends Field {
return this.buildError(messages);
}
getValue() {
serializeFromField() {
// TODO CLEAN
const usefulLinks = this.state.value;
let emptyIndexes = Array();
usefulLinks.map((el, idx) => {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment