NetTalk Central

Author Topic: ViewOnly but not all fields  (Read 5468 times)

Alberto

  • Hero Member
  • *****
  • Posts: 1873
    • MSN Messenger - alberto-michelis@hotmail.com
    • View Profile
    • ARMi software solutions
    • Email
ViewOnly but not all fields
« on: June 24, 2020, 08:00:32 AM »
Hi, I have a Form with many many controls and I need to set all disbaled by a condition.
This works ok.. but I need one or two fields to stay alive.
By ex... one is a checkbox, I set the readonly prop to false and I can change its value while in view only mode.
But ... the save button is hide and then the field is not saved.
So I added code to the validate of the chekbox to update it without need to save the form, but when I close the form the browse is not refreshed.
Any way of doing this?
-----------
Regards
Alberto

DonRidley

  • Don Ridley
  • Global Moderator
  • Hero Member
  • *****
  • Posts: 729
  • donaldridley2011@gmail.com
    • View Profile
    • Email
Re: ViewOnly but not all fields
« Reply #1 on: June 24, 2020, 02:26:59 PM »
I don't have an idea for your form but for the browse refresh you could play around with the GotFocusBack routine.

For example on one of my browse procedures I use this:

if p_web.GetValue('_from_') = 'payrolldeleteareyousureform'
    loc:stage = net:web:GenerateTable + net:web:UpdateNav + net:web:UpdateUpdates + net:web:UpdateHeadings + net:web:UpdateLocator + net:web:GenerateUpdates
    do GenerateBrowse
End

The payrolldeleteareyousureform (yes, long name LOL) form is a custom "delete" form but it is a memory form.

If you watch your browser's console log, you'll see the value for "_from_" being passed in the request.

It can get tricky doing stuff outside the realm of normal processes.  Just have to pay close attention to the values being passed and when the receiving procedure is expecting those values.  The timing is important.

To be honest, I avoid it if possible.

Good luck!

Don
"Eliminate the impossible, whatever remains, however unlikely, must be the truth."

NetTalk 12.55
Clarion 11

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11250
    • View Profile
Re: ViewOnly but not all fields
« Reply #2 on: June 24, 2020, 11:39:38 PM »
Hi Alberto,

>> I have a Form with many many controls and I need to set all disabled by a condition.

Since you start with a "lie" the rest just gets you deeper and deeper into trouble.

>> but I need one or two fields to stay alive.

so hence "not all disabled".

So do not set the "whole form to be readonly", since clearly' it's not the whole form.
Rather set the fields that have to be disabled to be disabled.

cheers
Bruce

Alberto

  • Hero Member
  • *****
  • Posts: 1873
    • MSN Messenger - alberto-michelis@hotmail.com
    • View Profile
    • ARMi software solutions
    • Email
Re: ViewOnly but not all fields
« Reply #3 on: June 25, 2020, 04:03:56 AM »
Bruce, I dont understand why Im a lier.

I said many many fields, add code for each one is... lets say... uncomfortable.

I am looking for an easy way to do this.

Will try the Don idea.
-----------
Regards
Alberto

Alberto

  • Hero Member
  • *****
  • Posts: 1873
    • MSN Messenger - alberto-michelis@hotmail.com
    • View Profile
    • ARMi software solutions
    • Email
Re: ViewOnly but not all fields
« Reply #4 on: June 25, 2020, 04:39:15 AM »
Thanks Don!!! excelent solution! it works ok
-----------
Regards
Alberto

DonRidley

  • Don Ridley
  • Global Moderator
  • Hero Member
  • *****
  • Posts: 729
  • donaldridley2011@gmail.com
    • View Profile
    • Email
Re: ViewOnly but not all fields
« Reply #5 on: June 26, 2020, 06:32:11 AM »
Bruce, I dont understand why Im a lier.

I don't think he was saying you are a liar.  He was saying your "view only" form was "lying."  It's a view only form but not really view only as it performs actions based on conditions. 

Don
"Eliminate the impossible, whatever remains, however unlikely, must be the truth."

NetTalk 12.55
Clarion 11

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11250
    • View Profile
Re: ViewOnly but not all fields
« Reply #6 on: June 29, 2020, 08:49:33 PM »
>> I don't think he was saying you are a liar.

yes I was :)

<< Bruce, I don't understand why I'm a liar.

Because you started by saying something that was not true. You said;

>> I need to set ALL disabled by a condition.

In truth what you meant to say was

>> I need to set MOST disabled by a condition.

Because you started with a "lie" (you told the template to set ALL to view-only) you then had to try and "undo" the lie, so to tell the template "except this and this and this".

>> I said many many fields, add code for each one is... lets say... uncomfortable.

So to liar we should add "lazy" ?   :)

And because you are lazy, you then look for shortcuts. So you resort to embedding code. The Form itself believes one thing (since you have set the template setting) but hey you can fix it by embedding code, and hoping that your code remains correct "forever".

Unfortunately Don has given you some terrible advice (because he's a helpful chap). Your solution to your laziness will work for now because the code is correct for the form being generated now. But in the long run it may not work because the template code may change. So your laziness now leads to "technical debt" - a possible problem later on.

Ultimately the best systems are the ones that have no embed code, or at least have embed code that _supplements_ what the templates do - not "bypasses" what the templates do.

In short, you saved yourself a few minutes now. But when it all breaks 2 years from now I predict there will be much wailing and gnashing of teeth. All because you are too lazy to actually do it right the first time....

[I'm not trying to be harsh - on you or Don - but sometimes bad habits need a rap across the knuckles.]

Now perhaps you should have identified the actual problem ("I'm too lazy to add this condition to most of the fields, is there an easier way?"). There's nothing wrong with being lazy (I'm very lazy) but knowing that, and fixing that problem is better than fixing some proxy problem.

cheers
Bruce