Search code examples
dartdart-html

Google Dart not pulling values from Input


I'm attempting to pull out date and time values from an HTML input but cannot seem to extract these values. It appears when trying to output the data in the browser console that it just says "input" and not the value itself. These would be in a form-like example but are meant for rest calls. See example below. Please let me know if you need more information.

HTML:

    <div id="dates">
      Start Date: <input type="date" id="start" name="start">
      Start Time: <input type="time" id="timestamp1" name="timestamp1" step="1">
      <br/>
      End Date:   <input type="date" id="end" name="end">
      End Time:   <input type="time" id="timestamp2" name="timestamp2" step="1">
    </div>

Dart:

    //capture dates
    var startDate = (shroot.querySelector('#start') as DateInputElement);
    var endDate = (shroot.querySelector('#end') as DateInputElement);
    var warn = (shroot.querySelector('#warning').text="");
    var timestamp1 = (shroot.querySelector("#timestamp1") as TimeInputElement);
    var timestamp2 = (shroot.querySelector("#timestamp2") as TimeInputElement);

    //button click to handle request
    button.onClick.listen((e) {
      print(startDate);
      print(endDate);
      print(timestamp1);
      print(timestamp2);
   });

Solution

  • As @melmac wrote

    button.onClick.listen((e) {
      print(startDate.value);
      print(startDate.valueAsDate);
      print(startDate.valueAsNumber);
    
      print(timestamp1.value);
      print(timestamp1.valueAsDate);
      print(timestamp1.valueAsNumber);
    

    });

    2014-07-17
    2014-07-17 02:00:00.000 // GMT !! 1405555200000.0

    11:12:13
    1970-01-01 12:12:13.000 // GMT !! 40333000.0