Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue with field.watch #378

Closed
JedWatson opened this issue May 22, 2014 · 7 comments
Closed

Issue with field.watch #378

JedWatson opened this issue May 22, 2014 · 7 comments
Labels

Comments

@JedWatson
Copy link
Member

As reported on the google group here: https://groups.google.com/forum/#!topic/keystonejs/snCB2F_KcVU

I am trying to use the watch feature and can not get it to watch another field.

This works:

total: { type: Types.Number, initial:true, default: '0.00' },
totalreceived: { type: Types.Number, initial:true, default: '0.00', label:'Received Total'  },
complete: { type: Boolean, watch: true, value: checkTotal }

...

function checkTotal() {
    return this.total<=this.totalreceived ? true:false;
}

If I try and watch the totalreceived field it does not work

complete: { type: Boolean, watch: 'totalreceived', value: checkTotal }
@JedWatson JedWatson added the bug label May 22, 2014
@DerekDomino
Copy link

Hello,

I confirm

platform: { type: Types.Select, options: 'node, ruby, python' },
usesKeystone: { type: String, watch: 'platform', value: testup},

...
var testup = function() {
    return "3";
}

Does the field watching occurs at the UI level when using a string for the watch entry of the Field definition?

@Ventis
Copy link

Ventis commented Jul 7, 2014

When is a fix for this expected?

@kraigh
Copy link

kraigh commented Jul 7, 2014

This is working for me, except it is actually watching the field above the "watched" field.

This is what my model looks like:

integration: { type: Types.Text },
source: { type: Types.Text },
lastUpdated: { type: Types.Datetime, default: Date.now, watch: 'integration', value: Date.now },

Updating the "integration" field does nothing, but updating the "source" field will cause the lastUpdated field to be updated.

@JedWatson
Copy link
Member Author

@DerekDomino it happens server-side, thanks to pre('save') middleware function that is added to the schema.

@kraigh that's really weird behaviour, hopefully it'll help me track down the issue.

@Ventis I'll try and tackle this one soon, I'd really like to fix it. If anyone else can dive in and help me figure out what's going wrong that'd be great, the relevant code is here:

https://github.com/JedWatson/keystone/blob/master/lib/field.js#L79

@Globegitter
Copy link
Contributor

Just to make this bug report complete:
headerPostTime: { type: Types.Datetime, default: null, label: 'Header Post', watch: { 'headerPost': true }, value: Date.now } doesn't seem to work either. Will try to look into this issue though.

@Globegitter
Copy link
Contributor

@JedWatson still looking into the issue, but saw that at least for _.isObject(this.options.watch) the issue seems to be that item.get('path') returns undefined (https://github.com/JedWatson/keystone/blob/master/lib/field.js#L105`
Will keep you updated/post a PR if I make progress.

Edit: Ok was an easy fix :P Will see if I can fix the rest and send a PR

@JedWatson
Copy link
Member Author

Thanks @Globegitter! I've merged that, and will push it in a new version to npm soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants