Discussion:
Making sure only one field is updated on a table update
(too old to reply)
Johnny
2010-08-25 14:05:03 UTC
Permalink
I have a problem which I have not found a good way of solving.

I got a field X. If the field X is set then ONLY the field Y is allowed to
be updated. How can I make sure that only field Y is being changed when
updating the table?

I would prefer to do this on the table level.
Luegisdorf
2010-08-26 13:30:03 UTC
Permalink
Hi Jonny

overwrite update() method on the subject table and put code similar to this:

{
anyType fieldValueWhichCanBeChanged = this.YOURFIELD; // isloate the
field value, which should be updated
;
this = this.orig(); // reset the buffer to the last load state
this.YOURFIELD = fieldValueWhichCanBeChanged; // apply only the isolated
field value

super();
}

But: if someone skips the data methods or use doUpdate(), you cannot react
on it. And keep in mind, this technique is out of best practice and seems bad
concept ...

May be you find a better way (he he, or should I say: may you find a better
way :)

Regards
Patrick
Post by Johnny
I have a problem which I have not found a good way of solving.
I got a field X. If the field X is set then ONLY the field Y is allowed to
be updated. How can I make sure that only field Y is being changed when
updating the table?
I would prefer to do this on the table level.
Johnny
2010-08-26 16:02:03 UTC
Permalink
Yes, that is probably not an acceptable solution :-)

If I change this to the form level. Is it possible to lock all fields for
editing except for one?
Post by Luegisdorf
Hi Jonny
{
anyType fieldValueWhichCanBeChanged = this.YOURFIELD; // isloate the
field value, which should be updated
;
this = this.orig(); // reset the buffer to the last load state
this.YOURFIELD = fieldValueWhichCanBeChanged; // apply only the isolated
field value
super();
}
But: if someone skips the data methods or use doUpdate(), you cannot react
on it. And keep in mind, this technique is out of best practice and seems bad
concept ...
May be you find a better way (he he, or should I say: may you find a better
way :)
Regards
Patrick
Post by Johnny
I have a problem which I have not found a good way of solving.
I got a field X. If the field X is set then ONLY the field Y is allowed to
be updated. How can I make sure that only field Y is being changed when
updating the table?
I would prefer to do this on the table level.
unknown
2010-08-26 20:13:04 UTC
Permalink
You can always lock the fields at the form level. You can either:
1) Disable all the controls. You can save doing it one by one by disabling
Groups. This will still require alot of work.
2) AllowEdit false on your datasource when field X is changed. And use an
edit method to update field Y.

I'd go with option 2... should be less code depending on how many fields
there are on the form.
--
Mathieu Vaillancourt
http://vaillancourtm.blogspot.com
Post by Johnny
Yes, that is probably not an acceptable solution :-)
If I change this to the form level. Is it possible to lock all fields for
editing except for one?
Post by Luegisdorf
Hi Jonny
{
anyType fieldValueWhichCanBeChanged = this.YOURFIELD; // isloate the
field value, which should be updated
;
this = this.orig(); // reset the buffer to the last load state
this.YOURFIELD = fieldValueWhichCanBeChanged; // apply only the isolated
field value
super();
}
But: if someone skips the data methods or use doUpdate(), you cannot react
on it. And keep in mind, this technique is out of best practice and seems bad
concept ...
May be you find a better way (he he, or should I say: may you find a better
way :)
Regards
Patrick
Post by Johnny
I have a problem which I have not found a good way of solving.
I got a field X. If the field X is set then ONLY the field Y is allowed to
be updated. How can I make sure that only field Y is being changed when
updating the table?
I would prefer to do this on the table level.
Luegisdorf
2010-08-27 13:06:03 UTC
Permalink
.. or

in form initialization you make a loop trough all fields of the table and
get the data field object (dataSource.object(fieldnum)) and set it to
allowEdit = false, if it should not be editet or to allowEdit = true, if it
should be editable.

This is easy to implement and all controls inherit from the dataObject (even
controls which are added by user or created at runtime). And you don't have
to create edit methods and you can leave the design as it is defined yet.

I would disadvice to modify properties direct on the controls, since this
works not for runtime created controls and not in every case of form
modification by user (and even it's best practice violation too :).

Regards
Patrick
Post by unknown
1) Disable all the controls. You can save doing it one by one by disabling
Groups. This will still require alot of work.
2) AllowEdit false on your datasource when field X is changed. And use an
edit method to update field Y.
I'd go with option 2... should be less code depending on how many fields
there are on the form.
--
Mathieu Vaillancourt
http://vaillancourtm.blogspot.com
Post by Johnny
Yes, that is probably not an acceptable solution :-)
If I change this to the form level. Is it possible to lock all fields for
editing except for one?
Post by Luegisdorf
Hi Jonny
{
anyType fieldValueWhichCanBeChanged = this.YOURFIELD; // isloate the
field value, which should be updated
;
this = this.orig(); // reset the buffer to the last load state
this.YOURFIELD = fieldValueWhichCanBeChanged; // apply only the isolated
field value
super();
}
But: if someone skips the data methods or use doUpdate(), you cannot react
on it. And keep in mind, this technique is out of best practice and seems bad
concept ...
May be you find a better way (he he, or should I say: may you find a better
way :)
Regards
Patrick
Post by Johnny
I have a problem which I have not found a good way of solving.
I got a field X. If the field X is set then ONLY the field Y is allowed to
be updated. How can I make sure that only field Y is being changed when
updating the table?
I would prefer to do this on the table level.
Loading...