@fto-consult/expo-ui 5.11.1 → 5.11.3

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": "5.11.1",
3
+ "version": "5.11.3",
4
4
  "description": "Bibliothèque de composants UI Expo,react-native",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -61,7 +61,7 @@
61
61
  "@emotion/native": "^11.11.0",
62
62
  "@expo/html-elements": "^0.2.0",
63
63
  "@expo/vector-icons": "^13.0.0",
64
- "@fto-consult/common": "^3.17.0",
64
+ "@fto-consult/common": "^3.17.9",
65
65
  "@gorhom/portal": "^1.0.14",
66
66
  "@react-native-async-storage/async-storage": "^1.17.11",
67
67
  "@react-native-community/datetimepicker": "^6.7.3",
@@ -27,28 +27,26 @@ export const close = (props)=>{
27
27
  }
28
28
 
29
29
  const Provider = React.forwardRef((props,innerRef)=>{
30
- const {onDismiss} = props;
31
30
  const ref = innerRef || createProviderRef();
32
- const [state,setState] = React.useState({
33
- visible : false,
34
- });
31
+ const [visible,setVisible] = React.useState(false);
32
+ const [state,setState] = React.useState({});
35
33
  const context = {
36
34
  open : (props)=>{
37
- return setState({onDismiss:undefined,...defaultObj(props),visible:true})
35
+ if(!visible){
36
+ setVisible(true);
37
+ }
38
+ setState(defaultObj(props));
38
39
  },
39
- close : (props)=>{
40
- return setState({...state,...defaultObj(props),visible:false})
40
+ close : ()=>{
41
+ if(visible) return;
42
+ setVisible(false);
41
43
  }
42
44
  };
43
45
  React.setRef(ref,context);
44
- return <Menu {...props} {...state} sheet controlled onDismiss = {(e)=>{
45
- setState({...state,visible:false});
46
- if(typeof state.onDismiss =='function'){
47
- state.onDismiss({context,state})
48
- } else if(onDismiss){
49
- onDismiss({context,state});
46
+ return <Menu {...props} {...state} visible={visible} sheet controlled onDismiss = {(e)=>{
47
+ if(visible){
48
+ setVisible(false);
50
49
  }
51
-
52
50
  }}/>
53
51
  });
54
52
 
@@ -41,32 +41,28 @@ export const close = (props,innerProviderRef)=>{
41
41
  }
42
42
 
43
43
  const Provider = React.forwardRef((props,innerRef)=>{
44
- const {onDismiss,beforeOpen} = props;
45
44
  const ref = innerRef || createProviderRef();
46
- const [state,setState] = React.useState({
47
- visible : defaultBool(props.visible,false),
48
- });
45
+ const [visible,setVisible] = React.useState(defaultBool(props.visible,false));
46
+ const [state,setState] = React.useState({});
49
47
  const context = {
50
48
  open : (props)=>{
51
- if(state.visible) return;
52
- let bfOpen = typeof state.beforeOpen == 'function'? state.beforeOpen : typeof beforeOpen =='function'? beforeOpen : x=>true;
53
- if(bfOpen(state) === false) return;
54
- return setState({onDismiss:undefined,...defaultObj(props),visible:true})
49
+ if(visible) {
50
+ return;
51
+ }
52
+ if(!visible){
53
+ setVisible(true);
54
+ }
55
+ setState(defaultObj(props));
55
56
  },
56
- close : (props)=>{
57
- if(!state.visible) return;
58
- return setState({...state,...defaultObj(props),visible:false});
57
+ close : ()=>{
58
+ if(!visible) return;
59
+ setVisible(false);
59
60
  },
60
61
  };
61
62
  React.setRef(ref,context);
62
- return <Dialog {...props} {...state} controlled onDismiss = {(e)=>{
63
- if(state.visible){
64
- setState({...state,visible:false});
65
- }
66
- if(typeof state.onDismiss =='function'){
67
- state.onDismiss({context,state});
68
- } else if(onDismiss){
69
- onDismiss({context,state});
63
+ return <Dialog {...props} {...state} visible={visible} controlled onDismiss = {(e)=>{
64
+ if(visible){
65
+ setVisible(false);
70
66
  }
71
67
  }}/>
72
68
  });
@@ -258,7 +258,13 @@ export default class Field extends AppComponent {
258
258
  let fields = getFormFields(this.formName);
259
259
  let canEnable = true;
260
260
  for(var k in fields){
261
- if(!fields[k].isValid()){
261
+ if(k === this.getName()) continue;
262
+ const fK = fields[k];
263
+ const matchF = fK.getMatchField();
264
+ if(matchF && matchF.getName() === this.getName()){
265
+ fK.validate({value:fK.getValue()});
266
+ }
267
+ if(!fK.isValid()){
262
268
  canEnable = false;
263
269
  break;
264
270
  }
@@ -285,7 +291,27 @@ export default class Field extends AppComponent {
285
291
  });
286
292
  });
287
293
  }
294
+ getMatchField (){
295
+ const matchField = defaultStr(this.props.matchField).trim();
296
+ return matchField && this.getField(matchField) || null;
297
+ }
298
+ validateMatchField (value){
299
+ if(this.isFilter()) return true;
300
+ const matchedField = this.getMatchField();
301
+ if(matchedField){
302
+ value = value !== undefined ? value : this.getValue();
303
+ const matchedValue = matchedField.getValue();
304
+ if(!React.isEquals(matchedValue,value)){
305
+ return `le champ [${matchedField?.getLabel()}] doit avoir la même valeur que celle du champ [${this.getLabel()}].`;
306
+ }
307
+ }
308
+ return true;
309
+ }
288
310
  onValidatorValid(args){
311
+ const valMatchField = this.validateMatchField();
312
+ if(isNonNullString(valMatchField)){
313
+ return valMatchField;
314
+ }
289
315
  if(!this.isFilter()){
290
316
  const vRule =defaultStr(this.getValidRule()).toLowerCase();
291
317
  const value = typeof args.value == "undefined" || args.value == null ? "" : String(args.value).replaceAll("/","").replaceAll("\\",'').trim();
@@ -747,7 +773,7 @@ export default class Field extends AppComponent {
747
773
  return;
748
774
  }
749
775
  if(this.isFilter()) return
750
- const value = this.getValue();
776
+ if(this.getMatchField())
751
777
  if(isNonNullString(this.props.fieldToPopulateOnBlur) && isNonNullString(value)){
752
778
  const context = this.getField(this.props.fieldToPopulateOnBlur.trim());
753
779
  if(context && context.getValue){
@@ -1122,6 +1148,7 @@ Field.propTypes = {
1122
1148
  * Lorsqu'elle est définie alors le rendu lors du composant doit être de type filter
1123
1149
  */
1124
1150
  renderfilter : PropTypes.string,
1151
+ matchField : PropTypes.string,//si cette valeur est définie, alors le champ figurant dans la valeur doit avoir la même valeur que le champ courant
1125
1152
  /**** il s'agit d'un champ du même formulaire que la formField actuel, qui sera populated avec la valeur par défaut
1126
1153
  * de la formField cournat loreque la valeur du champ en question a une longueur très inférieure à celle de la valeur de la form courante.
1127
1154
  */
@@ -14,24 +14,25 @@ const FormDataDialogProvider = React.forwardRef((props,innerRef)=>{
14
14
  innerRef = innerRef || createProviderRef((eRef)=>{
15
15
  dialogProviderRef = eRef;
16
16
  });
17
- const [state,setState] = React.useState({
18
- visible : false,
19
- });
17
+ const [visible,setVisible] = React.useState(false);
18
+ const [state,setState] = React.useState({});
20
19
  const isMobile = isMobileOrTabletMedia();
21
20
  const formRef = React.useRef(null);
22
- const {closeAction,onDismiss} = props;
21
+ const {closeAction} = props;
23
22
  const context = {
24
23
  open : (props)=>{
25
- if(state.visible) return;
26
24
  let sData = {};
27
25
  if(formRef.current && formRef.current.formDataContext && formRef.current.formDataContext.getData){
28
26
  sData.data = formRef.current.formDataContext.getData();
29
27
  }
30
- return setState({...sData,onDismiss:undefined,...defaultObj(props),visible:true})
28
+ if(!visible){
29
+ setVisible(true);
30
+ }
31
+ setState({...sData,...defaultObj(props)});
31
32
  },
32
- close : (props)=>{
33
- if(!state.visible) return;
34
- setState({...state,...defaultObj(props),visible:false});
33
+ close : ()=>{
34
+ if(!visible) return;
35
+ setVisible(false);
35
36
  },
36
37
  };
37
38
  React.setRef(innerRef,context);
@@ -52,6 +53,7 @@ const FormDataDialogProvider = React.forwardRef((props,innerRef)=>{
52
53
  subtitle ={false}
53
54
  {...props}
54
55
  {...state}
56
+ visible = {visible}
55
57
  formProps = {formProps}
56
58
  isProvider
57
59
  ref={formRef}
@@ -82,13 +84,8 @@ const FormDataDialogProvider = React.forwardRef((props,innerRef)=>{
82
84
  dialogProps = {dialogProps}
83
85
  controlled={false}
84
86
  onDismiss = {(e)=>{
85
- if(state.visible){
86
- setState({...state,visible:false});
87
- }
88
- if(typeof state.onDismiss =='function'){
89
- state.onDismiss({context,state});
90
- } else if(onDismiss){
91
- onDismiss({context,state});
87
+ if(visible){
88
+ setVisible(false);
92
89
  }
93
90
  }}
94
91
  open = {context.open}
@@ -54,8 +54,8 @@ const styles = StyleSheet.create({
54
54
  paddingLeft : 20,
55
55
  },
56
56
  checkbox : {
57
- width : 20,
58
- height : 20,
57
+ //width : 20,
58
+ //height : 20,
59
59
  margin : 0,
60
60
  padding: 0,
61
61
  }