0

I'm trying to make pop-up window when my form loads. And when you enter ID number in the pop-up window, it stores in the text-field in the form.

This is where u put the ID Number:

enter image description here

And this is where I want the value to be saved:

enter image description here

I'm using AgilePoint - and inside it I inserted JS code and sweetalert2. This is the code I'm trying to use:

eformEvents.onFormLoadComplete = function()

{Swal.fire({ //rtl:true 

title: 'title', html: '<p>hello</p>', icon:info, input:'text', inputLabel: 'Enter ID'

})

.then(inputValue) => {document.getElementById("Eid").Value = inputValue}

Swal.fire('Success')

})} 
Md. Rakibul Islam
  • 2,140
  • 1
  • 7
  • 14
  • You need to console log the `inputValue` in `then` handler. Which will tell you what is the key inside that object represents your value. This might be inputValue.value. – CodeThing Aug 18 '23 at 10:14
  • Thank you! :) there is possibility that i could add an action so it will hit 'enter' after the field has been updated with the ID ? – Shahar Hayoun Aug 18 '23 at 13:55

1 Answers1

0

SweetAlert then block will receive object. you need to pick value property from that object.

Try something like below.

// This is listener for keydown event 
document.getElementById("Eid").addEventListener('keydown', function(e) {
  if (e.keyCode === 13) { // enter is pressed
    console.log("Enter is pressed with value " + e.target.value);
  }
});

Swal.fire({
    title: 'title', html: '<p>hello</p>', input: 'text', inputLabel: 'Enter ID'
}).then(({value}) => {
  const elem = document.getElementById("Eid");
  elem.value = value;
  dispatchEnterEvent(elem);
  Swal.fire('Success');
});

function dispatchEnterEvent(elem) {
    const ev = new KeyboardEvent('keydown', {
      bubbles: true,
      cancelable: true,
      keyCode: 13
    });
    elem.dispatchEvent(ev);
}
CodeThing
  • 2,580
  • 2
  • 12
  • 25
  • Hey i've tried but it keeps telling me unexpected token }, – Shahar Hayoun Aug 18 '23 at 13:44
  • Have you tried this above code. The code which you shared in the question has some syntax issue. – CodeThing Aug 18 '23 at 13:55
  • Hey! yeah i've tried it, i've managed to store the ID value in the text field with inputvalue.value - but now i need it to trigger 'enter' action in the text field so the field will update. I mean after the ID stores in the textfield i want it to 'hit' the enter key. – Shahar Hayoun Aug 18 '23 at 14:05
  • You can just extract the logic (what you are doing after enter is pressed) into a function and call that function here after value is set. – CodeThing Aug 20 '23 at 04:47
  • um i think it's more complicated than that because the "function"(not really as function because i'm doing it in AgilePoint) supposed to fill several more fields with the ID that entered that is connect with SharePoint List to fill the other personal information. and the "function" isn't called unless it hits "enter" after i put the number in the ID filed. – Shahar Hayoun Aug 20 '23 at 12:34
  • Not sure what AgilePoint is but with JS you can dispatch the enter event on particular element. Check edited answer. – CodeThing Aug 21 '23 at 07:25