mirror of
https://github.com/LaCasemate/fab-manager.git
synced 2025-02-21 15:54:22 +01:00
(bug) fix save empty product image and is_main cannot set to new image after remove old main image
This commit is contained in:
parent
7e3cbf7172
commit
5de91acf88
@ -170,7 +170,7 @@ export const ProductForm: React.FC<ProductFormProps> = ({ product, title, onSucc
|
|||||||
*/
|
*/
|
||||||
const addProductImage = () => {
|
const addProductImage = () => {
|
||||||
setValue('product_images_attributes', output.product_images_attributes.concat({
|
setValue('product_images_attributes', output.product_images_attributes.concat({
|
||||||
is_main: output.product_images_attributes.length === 0
|
is_main: output.product_images_attributes.filter(i => i.is_main).length === 0
|
||||||
}));
|
}));
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -209,6 +209,7 @@ export const ProductForm: React.FC<ProductFormProps> = ({ product, title, onSucc
|
|||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
...image,
|
...image,
|
||||||
|
is_main: i === k ? false : image.is_main,
|
||||||
_destroy: i === k
|
_destroy: i === k
|
||||||
};
|
};
|
||||||
}));
|
}));
|
||||||
|
@ -15,7 +15,7 @@ class Product < ApplicationRecord
|
|||||||
accepts_nested_attributes_for :product_files, allow_destroy: true, reject_if: :all_blank
|
accepts_nested_attributes_for :product_files, allow_destroy: true, reject_if: :all_blank
|
||||||
|
|
||||||
has_many :product_images, as: :viewable, dependent: :destroy
|
has_many :product_images, as: :viewable, dependent: :destroy
|
||||||
accepts_nested_attributes_for :product_images, allow_destroy: true, reject_if: :all_blank
|
accepts_nested_attributes_for :product_images, allow_destroy: true, reject_if: ->(i) { i[:attachment].blank? }
|
||||||
|
|
||||||
has_many :product_stock_movements, dependent: :destroy
|
has_many :product_stock_movements, dependent: :destroy
|
||||||
accepts_nested_attributes_for :product_stock_movements, allow_destroy: true, reject_if: :all_blank
|
accepts_nested_attributes_for :product_stock_movements, allow_destroy: true, reject_if: :all_blank
|
||||||
|
Loading…
x
Reference in New Issue
Block a user