Forráskód Böngészése

new barcode scanner in products form

chemi ledon 7 éve
szülő
commit
ea2d9ac0ec

+ 10 - 18
app/views/products/_form.html.erb

@@ -300,14 +300,6 @@
   $(document).on('page:change', function() {
     App.init();
     $('.fileinput').fileinput();
-    <% if @product.barcode.blank? %>
-      $('body').barcodeListener().on('barcode.valid', function(e, code) {
-        if($('#product_barcode').length > 0) {
-          $('#product_barcode').val(code);
-          validateBarcode(code);
-        }
-      });
-    <% end %>
 
     presentaciones();
     // < % if @product.children.present? %>
@@ -321,16 +313,16 @@
     });
   });
 
-		<% if @product.barcode.blank? %>
-			// $('#product_barcode').codeScanner({       // SE ESTA TRIGGEREANDO AL ESCRIBIR TEXTO
-			// 	maxEntryTime: 500, // milliseconds
-			// 	minEntryChars: 5,  // characters
-			// 	onScan: function ($element, code) {
-			// 		$('#product_barcode').val(code);
-			// 		validateBarcode(code);
-			// 	}
-			// });
-		<% end %>
+	<% if @product.barcode.blank? %>
+		$('#product_barcode').codeScanner({
+			maxEntryTime: 100, // milliseconds
+			minEntryChars: 7,  // characters
+			onScan: function ($element, code) {
+				$('#product_barcode').val(code);
+				validateBarcode(code);
+			}
+		});
+	<% end %>
 
   $('#product_size_list').on('change', function(event) { getVariants(); });
   $('#product_color_list').on('change', function(event) { getVariants(); });

+ 4 - 2
app/views/products/_form_remote.html.erb

@@ -329,8 +329,10 @@
 		$('.fileinput').fileinput();
 
 		<% if @product.barcode.blank? %>
-			$('body').barcodeListener().on('barcode.valid', function(e, code) {
-				if($('#product_barcode').length > 0) {
+			$('#product_barcode').codeScanner({
+				maxEntryTime: 100, // milliseconds
+				minEntryChars: 7,  // characters
+				onScan: function ($element, code) {
 					$('#product_barcode').val(code);
 					validateBarcode(code);
 				}