openpim / server

Apache License 2.0
59 stars 24 forks source link

Required field needed and problem encountered #43

Open akramsarkis opened 2 days ago

akramsarkis commented 2 days ago
Field that is a drop down is required - [ ] I have a field that has identifier selectable_colors_frame, this one is a drop down with values coming from a list of values that identifie is frame, and I need this field to be required,, for this in my actions I added the below scripts but none worked: **Script 1** ```` // Validate the selectable_color_frame attribute if (!values.selectable_color_frame || values.selectable_color_frame.trim() === '') { throw new Error('Selectable Color Frame is required and cannot be empty.'); } ```` **Script 2** ```` // Get the value from the dropdown let frameValue = values.selectable_colors_frame; console.log('frameValue:', frameValue); // Log to check the structure // If frameValue is an object (with properties like id and frame or value), extract the 'frame' or 'value' field if (frameValue && typeof frameValue === 'object') { frameValue = frameValue.frame || frameValue.value; // Assuming 'frame' or 'value' holds the selected color/frame } // Now validate if the frame value is empty or not selected if (!frameValue || frameValue.trim() === '') { throw new Error('Selectable Color Frame is required and cannot be empty.'); } ```` - [ ] More of this I need to add a checkbox field and regarding if this checkbox is selected or not I should have 2 or 1 colors required, so what is the script to have such condition( One of the color is the one I described above )
designer name required - [ ] For the designer_name field that is a text, I am getting error values.designer_name.trim is not a function even though it is a text , note that it is a text language dependant Here the script I used ```` if (!values.designer_name || values.designer_name.trim() === '') { if (!item.values?.designer_name || item.values.designer_name.trim() === '') { throw new Error('Designer name is required and cannot be empty.'); } else { // Reset values.designer_name to the existing designer_name to prevent unintended save values.designer_name = item.values.designer_name; } } ````
Name required - [ ] I need the name field required, the one that is there by default when creating an item, after you create it the first fields are Identifier then Name and using the below script It returns the error I set even if the field is filled in ```` // Validate the name attribute if ((!values.name || values.name.trim() === '')) { if (!item.values?.name || item.values.name.trim() === '') { throw new Error('name is required and cannot be empty.'); } else { // Reset values.barcode to the existing barcode to prevent unintended save values.name = item.values.name; } } ````
akramsarkis commented 2 days ago

Thanks for your help @openpim