Просмотр исходного кода

Set default value if field is required

When creating or editing an endpoint, if a required field has no value
set, but it does have a default value, set the default value as the
actual value.
Sergiu Miclea 8 лет назад
Родитель
Сommit
915b1d7745

+ 1 - 1
src/components/pages/EndpointsPage/index.jsx

@@ -253,7 +253,7 @@ class EndpointsPage extends React.Component<{}, State> {
     if ((filterItem !== 'all' && (endpoint.type !== filterItem)) ||
     if ((filterItem !== 'all' && (endpoint.type !== filterItem)) ||
       (endpoint.name.toLowerCase().indexOf(filterText || '') === -1 &&
       (endpoint.name.toLowerCase().indexOf(filterText || '') === -1 &&
         // $FlowIssue
         // $FlowIssue
-        endpoint.description.toLowerCase().indexOf(filterText) === -1)
+        (!endpoint.description || endpoint.description.toLowerCase().indexOf(filterText) === -1))
     ) {
     ) {
       return false
       return false
     }
     }

+ 6 - 0
src/plugins/endpoint/default/SchemaPlugin.js

@@ -83,6 +83,12 @@ export const fieldsToPayload = (data: { [string]: mixed }, schema: SchemaPropert
   Object.keys(schema.properties).forEach(fieldName => {
   Object.keys(schema.properties).forEach(fieldName => {
     if (data[fieldName] && typeof data[fieldName] !== 'object') {
     if (data[fieldName] && typeof data[fieldName] !== 'object') {
       info[fieldName] = data[fieldName]
       info[fieldName] = data[fieldName]
+    } else if (
+      !data[fieldName] &&
+      schema.required && schema.required.find(f => f === fieldName) &&
+      schema.properties[fieldName].default
+    ) {
+      info[fieldName] = schema.properties[fieldName].default
     }
     }
   })
   })