@fto-consult/expo-ui 2.24.6 → 2.25.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fto-consult/expo-ui",
3
- "version": "2.24.6",
3
+ "version": "2.25.0",
4
4
  "description": "Bibliothèque de composants UI Expo,react-native",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -20,6 +20,7 @@ export const getCountryFieldProps = (props)=>{
20
20
  items : countries,
21
21
  upper : true,
22
22
  dialogProps : {title:'Sélectionner un pays'},
23
+ appConfigDefaultValueKey : "countryCode",
23
24
  getItemValue : ({item})=>item.code.toUpperCase(),
24
25
  renderText : ({item})=>"[{0}] {1}".sprintf(item?.code?.toUpperCase(),item?.label),
25
26
  compare : (a,b)=>{
@@ -1079,6 +1079,8 @@ Field.propTypes = {
1079
1079
  * lorsque allowWhiteSpace === false alors on vérifiera si le champ n'admet pas des caractères accentuées
1080
1080
  */
1081
1081
  allowWhiteSpaces : PropTypes.bool,
1082
+ autoSetDefaultValue : PropTypes.bool,//si la valeur par défaut sera définie automatiquement
1083
+ appConfigDefaultValueKey : PropTypes.string,//le nom de la clé des paramètres de configuration vers laquelle chercher la valeur par défaut
1082
1084
  }
1083
1085
 
1084
1086
  const styles = StyleSheet.create({
@@ -13,6 +13,7 @@ import {handleBeforeSaveCallback} from "./utils";
13
13
  import componentsTypes from "./componentsTypes";
14
14
  import { keyboardShortcuts } from "../utils";
15
15
  import {getScreenProps} from "$cnavigation";
16
+ import appConfig from "$capp/config";
16
17
 
17
18
  export default class FormDataComponent extends AppComponent{
18
19
  constructor(props){
@@ -192,6 +193,7 @@ export default class FormDataComponent extends AppComponent{
192
193
  } else if(isObj(field) && field.form !== false) {
193
194
  const name = defaultStr(field.name,field.field,index);
194
195
  const type = defaultStr(field.jsType,field.type,"text").trim().toLowerCase().replaceAll("_","");
196
+ const isDate = (type.contains('date') || type.contains('time'));
195
197
  const Component = componentsTypes[type] || componentsTypes.default;
196
198
  let {defaultValue,useDefaultValueFromData,hidden,renderFormDataField,getMediaQueryStyle,printLabels,queryLimit,selected,value,visible,dataFilesInterest,perm,ignore,form,responsiveProps:customResponsiveProps,...rest} = field;
197
199
  rest = Object.assign({},rest);
@@ -218,6 +220,14 @@ export default class FormDataComponent extends AppComponent{
218
220
  if(rest.defaultValue === null){
219
221
  rest.defaultValue = undefined;
220
222
  }
223
+ // les champs de type date par défaut qui sont requis, auront comme valeur par défaut la date actuelle s'il ne sont pas définies
224
+ if(rest.autoSetDefaultValue !== false && (!rest.defaultValue && typeof rest.defaultValue !=='boolean' && typeof rest.defaultValue !=='number')){
225
+ if(isDate && rest.required === true ){
226
+ rest.defaultValue = new Date();
227
+ } else if(!isDate && isNonNullString(rest.appConfigDefaultValueKey)){
228
+ rest.defaultValue = appConfigDefaultValueKey.get(rest.appConfigDefaultValueKey);
229
+ }
230
+ }
221
231
  customResponsiveProps = defaultObj(customResponsiveProps);
222
232
  content.push(<Component
223
233
  data = {data}
@@ -259,10 +259,6 @@ export default class TableDataScreenComponent extends FormDataScreen{
259
259
  if(currentField.visibleOnlyOnEditing === true && !isUpdated){
260
260
  currentField.form = false;
261
261
  }
262
- // les champs de type date par défaut qui sont requis, auront comme valeur par défaut la date actuelle s'il ne sont pas définies
263
- if(currentField.autoSetDefaultValue !== false && (type.contains('date') || type.contains('time')) && currentField.required === true && !currentField.defaultValue){
264
- currentField.defaultValue = new Date();
265
- }
266
262
  generatedColumnsProperties.map((f)=>{
267
263
  //on affiche les champs générés uniquement en cas de mise à jour
268
264
  if(currentField[f] === true){
@@ -870,7 +866,6 @@ TableDataScreenComponent.propTypes = {
870
866
  PropTypes.element,
871
867
  ]),
872
868
  showPreloaderOnUpsert : PropTypes.bool,//Si le preloader sera afficher en cas d'insertion/modification
873
- autoSetDefaultValue : PropTypes.bool,//si la valeur par défaut sera définie pour les champs de types date et time
874
869
  }
875
870
 
876
871
  const styles = StyleSheet.create({