Query: Autofil value in input fields with extension

My question is how do we save autofilled value(using extension) in input fields of edit forms? I mean i am successfully able to autofill required values into some input field using extension, but those value dont stick to the input field, autofilled value vanishes as soon as i type or click in other input fields/ or when i click create(update) button.
Can anyone please suggest, if saving autofilled value (getting it to stick permanently to input field) be achieved by adding or overwriting some attribute of that input field or by some other method…

This seems related to a topic and further posts you created last year at Adding- autofill discount option in customer/supplier especially post 18:

It was made clear in post 8 by @Lubos that Manager does not have this capacity until:

Also when trying to write and extension even though as you acknowledge an obsolete feature and thus not supported that to have any success in getting support that you should show us your attempt in code and where relevant screenshots if to get any help with coding.

I flagged your post because it puts 2 issues in one topic and therefore is much better to have 2 separate topics to prevent total confusion as to which of the 2 topics is under discussion, for example I am now replying to your second issue.

edited the topic & my initial post to follow forum standards.

1 Like

@BawarYassin @AntonisV any suggestions?

const input = document.querySelector(“css selector of input field”);
let my_desired_input_value = 1; // for example
input.value = my_desired_input_value ;

this example code successfully fills input field with value stored in my_desired_input_value i.e 1
But typing or clicking on any other input field of the edit screen clears the autofilled value in the input field.

I have tried set/change “autocomplete” attribute of input field to “on”, but even though attribute is set succesfully as"on", autofilled value still doesnt stick to the field.

the html page saves value only if it recognizes change event in the input field, which apparently is not fulfilled by autofill value, it considers change only by typing, or clicking some character, otherwise it does not considers programatically filled value as change to the edit form

You need to trigger change event manually and wait for content to be loaded.

document.addEventListener(“DOMContentLoaded”, function() {
const input = document.querySelector(“div > span > input.form-control.input-sm.tt-input”);
let my_desired_input_value = 1; // for example
input.value = my_desired_input_value;

// Create a new “change” event
const changeEvent = new Event(“change”, { bubbles: true });
input.dispatchEvent(changeEvent);
console.log(“all good”);
});

@BawarYassin have you ever used or use extension to autofill input fields? Because the code that you have shared still does not permanently insert the autofilled value. I am currently using Desktop/Server version 23.8.20.964 .What i am currently doing as workaround is I am making focus shift at the end of autofilled value & manually pressing spacebar key(manually adding some character) to save the value permanently into the input field. Adding blank space at the end does not affect the input value also this way. But again, this involves manually saving by pressing some key, & autofilling process is still not fully automated.

have you ever been able to make it work??

In that case, you will need to use something called mutation observer. It’s hard to setup but it will work.

Thank you so much @BawarYassin. I have learnt a lot with your guidance. :slightly_smiling_face:

1 Like