Show in console the data from form with Dojo

165 views Asked by At

I have a problem showing in my console the data that the user puts in the input (only using Dojo, once the Submit button is pressed). Right now it shows "Name: [Widget dijit.form.TextBox, dijit_form_TextBox_2]"

My HTML code that is not dynamic:

  <div class="NameContainer">
    <label class="label1" for="name">Name:</label>
    <input data-dojo-attach-point="nameInputData" type="text" name="name1"
        data-dojo-type="dijit/form/TextBox"
        data-dojo-props="trim:true, propercase:true"/>
  </div>
<button data-dojo-type="dijit.form.Button" type="button"  data-dojo-attach-point="submitButton"  data-dojo-attach-event="onClick:_submitDetails">Submit</button>

JS function (I have also tried this.nameData.value, but it seems it does not exist):

_submitDetails: function () {
      var nameData = this.nameData;
      console.log("Name: " + nameData);
    }
1

There are 1 answers

0
Ruan Mendes On BEST ANSWER

Use a , instead of a +, that will pass a separate argument that is clickable on the screen instead of calling toString() on the object to concatenate it with a string.

console.log("Name: ", nameData);

I actually prefer the following since it gives you the name of the variable

console.log({nameData});

For those with non-interactive consoles, such as node JS, you can use JSON.stringify to turn it into a readable string, as long as the object doesn't have cyclical references