Skip to Content
Menu
This question has been flagged
1 Reply
2317 Views

Hi,

in the Barcode Operation screen, I am trying to split the barcode into (barcode, date, and lot) and show every part of these 3 into corresponding fields in XML 

I found a way to split the barcode into 3 variables after the barcode  scanned, 

the question is: How to fill the corresponding fields (barcode, lot name, expiration date) in XML?

in general, what is the connection between js and XML files??

Avatar
Discard
Best Answer

In Odoo, the relationship between JavaScript and XML files is that XML files are used to define the structure and layout of views, while JavaScript is used to add logic and interactivity to the views. In your case, you can use JavaScript to split the barcode into its different parts, and then use the $el property of the view to access the corresponding XML elements and update their values.

For example, to set the value of a field with the id attribute set to barcode_field, you can use the following code:

var barcodeField = this.$el.find('#barcode_field');
barcodeField.val(barcodeValue);

This code will find the element with the id attribute set to barcode_field in the view's XML, and set its value to barcodeValue. You can use a similar approach to set the values of the other fields.

Keep in mind that you need to make sure that the JavaScript code is executed after the view has been rendered, so you may need to use a deferred object or the on_attach_callback function to make sure that the fields are available when the code is executed.

Avatar
Discard
Related Posts Replies Views Activity
1
Jun 24
266
1
Aug 20
7681
2
Jun 20
2893
2
Jul 24
287
2
Jun 23
40696