Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

So I have a client controller like so (with only relevant code):

angular.module('employees').controller('EmployeesController', ['$scope', '$stateParams', '$location', 'Authentication', 'Employees',
    function($scope, $stateParams, $location, Authentication, Employees) {
        $scope.authentication = Authentication;

        // Create new Employee
        $scope.create = function() {
            // Create new Employee object
            var employee = new Employees ({
                name: this.name,
                eid: this.eid,
                availibility: [monday: this.monday, tuesday: this.tuesday]
            });

With a client view (again, only code relevant to the availability array)

<div class="form-group form-inline">
                    <label class="control-label" for="monday">Monday</label>             
                    <label class="control-label" for="start">Start</label>             
                    <label class="control-label" for="finish">Finish</label>             
                    <div class="controls">
                      <input type="checkbox" id="monday" class="form-control" required>
                      <input type="time" id="start" class="form-control" required> <input type="time" id="finish" class="form-control" required>
                    </div>
                </div>
                <div class="form-group form-inline">
                    <label class="control-label" for="tuesday">Tuesday</label>
                    <label class="control-label" for="start">Start</label>             
                    <label class="control-label" for="finish">Finish</label>             
                    <div class="controls">
                      <input type="checkbox" id="tuesday" class="form-control" required>
                      <input type="time" id="start" class="form-control" required>
                      <input type="time" id="finish" class="form-control" required>                    
                    </div>
                </div>

And a server controller like so:

exports.create = function(req, res) {
    var employee = new Employee(req.body);
    employee.user = req.user;
    console.log(req.body);
    employee.save(function(err) {
        if (err) {
            return res.status(400).send({
                message: errorHandler.getErrorMessage(err)
            });
        } else {
            res.jsonp(employee);
        }
    });
};

How can I make it so that the user can update an "availability" schedule? For some reason, when I POST the form, all I am getting is the eid and name (in the req.body). What am I doing wrong here? Can anyone point me in the direction of a resource that I could use?

Also, another question that kinda has something to do with this: Can I use ngTable to style these forms? As in, can I put forms inside of a table?

Thanks everybody for the help!

P.S. I realize the code is pretty dirty (particular the HTML code + the fact that none of my controllers are actually trying to pull data from the forms yet). Again, I don't have any real reason to continue on to that part until I know why when I POST the form, the data is not included in the post.

share|improve this question

1 Answer 1

Things to try:

  • Verify spelling of availability you have availibility in your create function and it could be an issue with your setup.
  • It looks like you are probably using a mean.js-like setup. I would first confirm that you have added the availability field to your Employee object. In this case you would have to make the file app/model/employee.server.model.js (or where ever your model definition is to have the array)

_

new Employee({
    name: {type: String},
    eid: {type: String},
    availibility: {type: Array,
        default: []
    }
}
  • Finally your create function looks a little funky to me. I would use a more standard definition for the array

    // Create new Employee
    $scope.create = function() {
        // Create new Employee object
        var employee = new Employees ({
            name: this.name,
            eid: this.eid,
            availibility: [this.monday, this.tuesday]
        }); 
    
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.