cirandas.net

commit 97bebda279be43c822c5f56cd6cc55497ff8328c

Author: Hugo Melo <hugo@riseup.net>

Fix product category validation

 plugins/suppliers/public/javascripts/views/product-modal.tag.slim | 14 


diff --git a/plugins/suppliers/public/javascripts/views/product-modal.tag.slim b/plugins/suppliers/public/javascripts/views/product-modal.tag.slim
index 23661359a88a4fac7fc39773e89ec463b8fff69b..f9533cf1b9f259d0755330637a403d41fc993306 100644
--- a/plugins/suppliers/public/javascripts/views/product-modal.tag.slim
+++ b/plugins/suppliers/public/javascripts/views/product-modal.tag.slim
@@ -14,7 +14,7 @@             h1.title if="{product.id}"
               |{product.name}
             h1.title if="{!product.id}"
               |{t('views.product.add_product')}
-  
+
       .modal-body
         .row
           .col-xs-12.col-md-5
@@ -45,7 +45,7 @@               .form-group
                 label for="p-description"
                   |{t("views.product.description")}
                 textarea value="{product.description}" id="p-description"
-                
+
               .form-group
                 label for="p-product_category_id"
                   |{t("views.product.category")}
@@ -107,7 +107,7 @@         a href="" onclick="{remove}" class="remove_product" if="{product.id}"
           |{t('views.product.remove')}
         span.warning if="{product.id}"
           |{t('views.product.remove_warning')}
-          
+
 
   javascript:
     this.t = window.products.t
@@ -151,7 +151,7 @@       if (!this.product.id)
         keys.push('supplier_id')
 
       var self = this;
-      
+
       keys.forEach(function(key) {
         var input = self["p-"+key];
 
@@ -220,14 +220,14 @@     }
 
     validate() {
       var keys = ['name', "supplier_id",'product_category_id']
-      
+
       for (var i in keys) {
         var input = this["p-"+keys[i]]
 
         if (keys[i] == 'supplier_id' && this.product.id)
           continue;
         // to validate category need to see the id instead of the input
-        if (keys[i] == 'product_category_id' && !this.product.product_category_id)
+        if (keys[i] == 'product_category_id' && typeof(this.product.product_category_id) == "string")
           input.value = ""
         if (input.value.trim() == "" || input.value == "0") {
           alert(this.t('views.product.validation_error_'+keys[i]))
@@ -241,7 +241,7 @@
     saveImage() {
       var self = this
       var saveUrl = Routes.suppliers_plugin_product_path({profile: noosfero.profile, action: 'set_image/'+this.product.id})
-      
+
       data = new FormData();
       data.append('image_builder', $('#image')[0].files[0])
       var opts = {