mftsccs-browser 1.1.35-beta → 1.1.36-beta

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.
@@ -7827,8 +7827,8 @@ class LocalSyncData {
7827
7827
  else {
7828
7828
  console.warn('Syncing this way has been Depreceted in service worker.');
7829
7829
  console.info('Only if serive worker is not running');
7830
- conceptsArray = this.conceptsSyncArray.slice();
7831
- connectionsArray = this.connectionSyncArray.slice();
7830
+ conceptsArray = this.conceptsSyncArray.slice() || [];
7831
+ connectionsArray = this.connectionSyncArray.slice() || [];
7832
7832
  // return []
7833
7833
  }
7834
7834
  this.connectionSyncArray = [];
@@ -17864,6 +17864,7 @@ __webpack_require__.r(__webpack_exports__);
17864
17864
  * @returns - An object containing the field's value and constraints (type, maxLength, etc.).
17865
17865
  */
17866
17866
  const createFormFieldData = (fieldName) => {
17867
+ var _a;
17867
17868
  const inputElements = document.getElementsByName(fieldName);
17868
17869
  const inputElement = inputElements[0];
17869
17870
  // Check if the element exists
@@ -17871,13 +17872,16 @@ const createFormFieldData = (fieldName) => {
17871
17872
  console.warn(`Element with NAME "${fieldName}" not found.`);
17872
17873
  return {
17873
17874
  value: null,
17875
+ fieldType: null,
17874
17876
  dataType: null,
17877
+ pattern: null,
17875
17878
  conceptType: null,
17876
17879
  maxLength: null,
17877
17880
  minLength: null,
17878
17881
  minValue: null,
17879
17882
  maxValue: null,
17880
17883
  accept: null,
17884
+ file: null,
17881
17885
  required: false,
17882
17886
  isUnique: true
17883
17887
  };
@@ -17888,13 +17892,16 @@ const createFormFieldData = (fieldName) => {
17888
17892
  // Proceed to gather data if the element exists
17889
17893
  const data = {
17890
17894
  value: inputElement.value,
17895
+ fieldType: inputElement.type,
17891
17896
  dataType: inputElement.getAttribute('data-type'),
17897
+ pattern: inputElement.getAttribute('data-pattern'),
17892
17898
  conceptType: inputElement.getAttribute('concept-type'),
17893
17899
  maxLength: inputElement.getAttribute('data-maxlength') ? parseInt(inputElement.getAttribute('data-maxlength')) : null,
17894
17900
  minLength: inputElement.getAttribute('data-minlength') ? parseInt(inputElement.getAttribute('data-minlength')) : null,
17895
17901
  minValue: inputElement.getAttribute('data-min') ? parseInt(inputElement.getAttribute('data-min')) : null,
17896
17902
  maxValue: inputElement.getAttribute('data-max') ? parseInt(inputElement.getAttribute('data-max')) : null,
17897
17903
  accept: inputElement.getAttribute('accept') || null,
17904
+ file: inputElement.type === 'file' ? ((_a = inputElement.files) === null || _a === void 0 ? void 0 : _a[0]) || null : null,
17898
17905
  required: required,
17899
17906
  isUnique: isUnique
17900
17907
  };
@@ -17968,55 +17975,63 @@ class Validator {
17968
17975
  * @param file - The file input (if any), used for file type validation.
17969
17976
  * @param required - Whether the field is required.
17970
17977
  * @param isUnique - Whether the field value should be unique.
17971
- * @returns An array of error messages if validation fails, or an empty array if the field is valid.
17978
+ * @returns An object of error messages if validation fails
17972
17979
  */
17973
- validateField(fieldName_1, dataType_1, value_1, conceptType_1, maxLength_1, minLength_1, minValue_1, maxValue_1, accept_1, file_1, required_1) {
17974
- return __awaiter(this, arguments, void 0, function* (fieldName, dataType, value, conceptType, maxLength, minLength, minValue, maxValue, accept, file, required, isUnique = false // Optional parameter for uniqueness check
17975
- ) {
17980
+ validateField(fieldName_1, fieldType_1, dataType_1, value_1, pattern_1, conceptType_1, maxLength_1, minLength_1, minValue_1, maxValue_1, accept_1, file_1, required_1) {
17981
+ return __awaiter(this, arguments, void 0, function* (fieldName, fieldType, dataType, value, pattern, conceptType, maxLength, minLength, minValue, maxValue, accept, file, required, isUnique = false) {
17976
17982
  var _a;
17977
- const errors = [];
17983
+ const errors = {};
17978
17984
  // 1. Validate required field (must not be empty)
17979
17985
  if (required && (value === null || value === '')) {
17980
- errors.push(`${fieldName} is required`);
17986
+ errors['required'] = `this is required field`;
17981
17987
  }
17982
17988
  // 2. Validate using regex pattern for the data type
17983
17989
  if (dataType && value) {
17984
- const pattern = _constant__WEBPACK_IMPORTED_MODULE_1__.DATA_TYPES_RULES[dataType];
17990
+ console.log(`Comment on Data Type ${dataType} and Value ${value}`);
17991
+ let pattern = _constant__WEBPACK_IMPORTED_MODULE_1__.DATA_TYPES_RULES[dataType];
17992
+ console.log("Find Pattern : ", pattern);
17985
17993
  if (pattern && value !== '' && !pattern.test(value)) {
17986
- errors.push(`Invalid format for ${dataType} in ${fieldName}`);
17994
+ errors['dataType'] = `Invalid format for ${dataType} in ${fieldName}`;
17987
17995
  }
17988
17996
  }
17989
- // 3. Validate maxLength
17997
+ // 3. Check if the provided pattern match with the value or not
17998
+ if (pattern && value) {
17999
+ const regex = typeof pattern === 'string' ? new RegExp(pattern) : pattern;
18000
+ if (value !== '' && !regex.test(value)) {
18001
+ errors['pattern'] = `Pattern doesn't match with data`;
18002
+ }
18003
+ }
18004
+ // 4. Validate maxLength
17990
18005
  if (value && maxLength !== null && value.length > maxLength) {
17991
- errors.push(`${fieldName} exceeds the maximum length of ${maxLength}`);
18006
+ errors['maxLength'] = `length exceeds the maximum length of ${maxLength}`;
17992
18007
  }
17993
- // 4. Validate minLength
18008
+ // 5. Validate minLength
17994
18009
  if (value && minLength !== null && value.length < minLength) {
17995
- errors.push(`${fieldName} must be at least ${minLength} characters long`);
18010
+ errors['minLength'] = `length must be at least ${minLength} characters long`;
17996
18011
  }
17997
- // 5. Validate minValue (only for numeric fields)
18012
+ // 6. Validate minValue (only for numeric fields)
17998
18013
  if (minValue !== null && value && !isNaN(Number(value)) && Number(value) < minValue) {
17999
- errors.push(`${fieldName} must be greater than or equal to ${minValue}`);
18014
+ errors['minValue'] = `value must be greater than or equal to ${minValue}`;
18000
18015
  }
18001
- // 6. Validate maxValue (only for numeric fields)
18016
+ // 7. Validate maxValue (only for numeric fields)
18002
18017
  if (maxValue !== null && value && !isNaN(Number(value)) && Number(value) > maxValue) {
18003
- errors.push(`${fieldName} must be less than or equal to ${maxValue}`);
18018
+ errors['maxValue'] = `value must be less than or equal to ${maxValue}`;
18004
18019
  }
18005
- // 7. File validation: Check if this is a file input
18006
- if (dataType === 'file' && file) {
18007
- if (accept) {
18020
+ // 8. File validation: Check if this is a file input
18021
+ if (file) {
18022
+ if (fieldType && accept) {
18008
18023
  const acceptedTypes = accept.split(',').map(type => type.trim().toLowerCase());
18009
18024
  const fileExtension = (_a = file.name.split('.').pop()) === null || _a === void 0 ? void 0 : _a.toLowerCase();
18010
18025
  if (fileExtension && !acceptedTypes.includes(fileExtension)) {
18011
- errors.push(`${fieldName} must be a valid file type: ${acceptedTypes.join(', ')}`);
18026
+ errors['accept'] = `file must be a valid file type: ${acceptedTypes.join(', ')}`;
18012
18027
  }
18013
18028
  }
18014
18029
  }
18015
- // 8. Check if the field needs to be unique and perform uniqueness validation
18030
+ // 9. Check if the field needs to be unique and perform uniqueness validation
18016
18031
  if (conceptType && isUnique && value) {
18017
18032
  const isUniqueValue = yield this.checkUniqueness(conceptType, value);
18018
18033
  if (!isUniqueValue) {
18019
- errors.push(`${fieldName} is not unique`);
18034
+ errors['unique'] = `value is not unique`;
18020
18035
  }
18021
18036
  }
18022
18037
  return errors;
@@ -18037,13 +18052,11 @@ class Validator {
18037
18052
  const validationErrors = {};
18038
18053
  // Iterate through the fields in the form data
18039
18054
  for (const fieldName in formData) {
18040
- const { value, dataType, conceptType, maxLength = null, minLength = null, minValue = null, maxValue = null, accept = null, file = null, required, isUnique } = formData[fieldName];
18055
+ const { value, fieldType, dataType, pattern, conceptType, maxLength = null, minLength = null, minValue = null, maxValue = null, accept = null, file = null, required, isUnique } = formData[fieldName];
18041
18056
  // Call the validateField function to validate each field
18042
- const fieldErrors = yield this.validateField(fieldName, dataType, value, conceptType, maxLength, minLength, minValue, maxValue, accept, file, required, isUnique);
18043
- // If there are errors, add them to the errors object
18044
- if (fieldErrors.length > 0) {
18057
+ const fieldErrors = yield this.validateField(fieldName, fieldType, dataType, value, pattern, conceptType, maxLength, minLength, minValue, maxValue, accept, file, required, isUnique);
18058
+ if (Object.keys(fieldErrors).length > 0)
18045
18059
  validationErrors[fieldName] = fieldErrors;
18046
- }
18047
18060
  }
18048
18061
  return validationErrors;
18049
18062
  });