Real Time Data As Per Selection

I am having some fields and a message box. What I want is when I insert some values in field A, that value is automatically inserted and shown to message box without clickon on save. Want to achieve so by custom script. Any approach ??

1 Like

Share a screenshot

Like here, If i insert any value or select any category, that value or option will be automatically inserted to your message box, without saving or anything

Do these values exist in some document or they will be calculated on demand ?

in same document

Okay then it will be a simple case of concatenating strings into one single message via JS. Have you written a custom script as of yet ?

But what I am asking is I am filling those vales on realtime too, so they aren’t stored on database. Can I get those vales on live and push it to message box ?

set the value of message box to the value of category

frappe.ui.form.on("DocType", "category", function(frm, cdt, cdn) {
	frm.set_value('message_box', frm.doc.category);
});

Actually I want that value automatically gets inserted as i typed in a field. By using above script, I had to save it first then it gets fetched thats what I didn’t want.

No it works on field change. once you type and press tab.

if you need every letter typed to be applied to another field, then use jquery keyup/keydown method

Naah, either I had to press on save button or put

 frm.save();

along with the code mentioned by you in custom script.

Looking forward to do the same using jQuery

Edit

frm.doc.message_box = “abc”
refresh_field(“message_box”)

if using frm.set_value, no need to refresh_field.

1 Like

updated my code, try again

Working now but i need to do the same for about 25 to 30 fields, so trying to do that with jQuery in a hope that tere will be less lines of code.

Thanks BTW

Just for a info, frm.set value sets value for a one field. What if I want to set values from a multiple fields (in a custom sequence) to my message box ?

frm.set_value({
  "wip_warehouse": "Work In Progress",
  "fg_warehouse": item_group
});

This sets multiple field values.

Concatenate the values and set the value to message box.

I am having trouble in putting the values in a common field “your_message”. When i fill the value and open the array via console.log, then value exists but when checking frist and entering the values that time then no changes happens. I want is I get all the values in different variable so that I can compose a messgae body. But guess like its only working on page loading. Tried even refresh_field but that also didn’t changed aything. Here’s my code:

var lot_data=[];
frappe.ui.form.on("Draft", "lots", function(frm, cdt, cdn) {
	
if(frm.doc.lots){
lot_data['lots']=frm.doc.lots;
}
else{
lot_data['lots']=' ';
}
//console.log(lot_data.lots);
});
//var zz='';
frappe.ui.form.on("Draft", "action", function(frm, cdt, cdn) {

if(frm.doc.action){
lot_data['action']=frm.doc.action;
}
else{
lot_data['action']= '';
}
//console.log(lot_data.action);
//zz=lot_data.action;
});
//cur_frm.set_value('your_message',zz);
frappe.ui.form.on("Draft","refresh",function(frm,cdt,cdn) {
cur_frm.set_value('your_message',lot_data.action);
});

When do you want to set_value to your_message?

if you have many triggered fields, you can do as below:

frappe.ui.form.on("Draft", {
  lots: function(frm){
    // code
    set_value_message(frm);
  },
  action: function(frm){
    // code
    set_value_message(frm);
  },
  refresh: function(frm){
    //code 
    set_value_message(frm);
  }
});

var set_value_message = function(frm){
  frm.set_value("your_message", frm.doc.action);
}

i want all those values at last for composing the message. Best will be it got fetched to message box as soon as I type (without pressing tab for text field). Although I tried your way but it just puts “undefined” in the messge box

frappe.ui.form.on("Draft", {
  lots: function(frm){
   if(frm.doc.lots){
var lot = frm.doc.lots + " LOTS OF";
}
else{
var lot = frm.doc.lots='';
}
  },
  action: function(frm){
    if(frm.doc.action){
var action=frm.doc.lots;
}
else{
var action = frm.doc.action='';
}
  },
  refresh: function(frm){
    frm.set_value("your_message",action);
  }
})

Thats The Code

Also with

frm.set_value("your_message",frm.doc.action +" "+ frm.doc.lots);

Nothing Changed