[Vtigercrm-developers] vt7: How to update field from Javascript

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

[Vtigercrm-developers] vt7: How to update field from Javascript

Alan Lord (News)
What's the "trick" to update/alter the value of a field using Javascript?

I Detailview I am trying something like:

> jQuery('input[data-name="svc_charges"]').data('value', myNewValue);

But the attributes do not seem to be updating and nor is the span with
the display value in it?

is there something I need to "trigger" to get this to update?

TIA

Al


_______________________________________________
http://www.vtiger.com/
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: vt7: How to update field from Javascript

Susruthan Seran
Hi Alan

Is that a input?

Seran


On 01/20/2017 07:26 PM, Alan Lord wrote:

> What's the "trick" to update/alter the value of a field using Javascript?
>
> I Detailview I am trying something like:
>
>> jQuery('input[data-name="svc_charges"]').data('value', myNewValue);
>
> But the attributes do not seem to be updating and nor is the span with
> the display value in it?
>
> is there something I need to "trigger" to get this to update?
>
> TIA
>
> Al
>
>
> _______________________________________________
> http://www.vtiger.com/

_______________________________________________
http://www.vtiger.com/
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: vt7: How to update field from Javascript

Alan Lord (News)
On 20/01/17 14:36, Susruthan Seran wrote:
> Hi Alan
>
> Is that a input?

Yes. In vt7 the fields (in DetailView at least) are marked up like this:

> <td class="fieldValue " id="LSSvcSVS_detailView_fieldValue_svc_charges">
>   <span class="value" data-field-type="currency">
>     <span class="currencyValue">0</span>
>   </span>
>   <span class="hide edit pull-left">
>   <input class="fieldBasicData" data-name="svc_charges" data-type="currency" data-displayvalue="0" data-value="0.00" type="hidden">
>   </span>
>   <span class="action pull-right">
>     <a href="#" onclick="return false;" class="editAction fa fa-pencil">
>     </a>
>   </span>
> </td>

Al

> On 01/20/2017 07:26 PM, Alan Lord wrote:
>> What's the "trick" to update/alter the value of a field using Javascript?
>>
>> I Detailview I am trying something like:
>>
>>> jQuery('input[data-name="svc_charges"]').data('value', myNewValue);
>>
>> But the attributes do not seem to be updating and nor is the span with
>> the display value in it?
>>
>> is there something I need to "trigger" to get this to update?


_______________________________________________
http://www.vtiger.com/
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: vt7: How to update field from Javascript

Susruthan Seran
Try this..

jQuery('input[data-name="svc_charges"]').attr('data-displayvalue',100);


On 01/20/2017 08:23 PM, Alan Lord wrote:

> On 20/01/17 14:36, Susruthan Seran wrote:
>> Hi Alan
>>
>> Is that a input?
>
> Yes. In vt7 the fields (in DetailView at least) are marked up like this:
>
>> <td class="fieldValue " id="LSSvcSVS_detailView_fieldValue_svc_charges">
>>   <span class="value" data-field-type="currency">
>>     <span class="currencyValue">0</span>
>>   </span>
>>   <span class="hide edit pull-left">
>>   <input class="fieldBasicData" data-name="svc_charges"
>> data-type="currency" data-displayvalue="0" data-value="0.00"
>> type="hidden">
>>   </span>
>>   <span class="action pull-right">
>>     <a href="#" onclick="return false;" class="editAction fa fa-pencil">
>>     </a>
>>   </span>
>> </td>
>
> Al
>
>> On 01/20/2017 07:26 PM, Alan Lord wrote:
>>> What's the "trick" to update/alter the value of a field using
>>> Javascript?
>>>
>>> I Detailview I am trying something like:
>>>
>>>> jQuery('input[data-name="svc_charges"]').data('value', myNewValue);
>>>
>>> But the attributes do not seem to be updating and nor is the span with
>>> the display value in it?
>>>
>>> is there something I need to "trigger" to get this to update?
>
>
> _______________________________________________
> http://www.vtiger.com/

_______________________________________________
http://www.vtiger.com/
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: vt7: How to update field from Javascript

Alan Lord (News)
On 20/01/17 15:19, Susruthan Seran wrote:
> Try this..
>
> jQuery('input[data-name="svc_charges"]').attr('data-displayvalue',100);

It's getting somewhere...

In firebug that element now looks like:

> <input class="fieldBasicData" data-name="svc_charges" data-type="currency" data-displayvalue="2264.177655529488" data-value="0.00" type="hidden">

But this has not updated the value visible to the end-user. This is in
the two nested <span> above the input tag...

I would have assumed that there would be some kind of API for this kind
of thing in the Detail_js class or similar but I've been hunting around
the code and can't find anything.

And picklists are just a nightmare... They really do seem to be empty
until you click the pencil icon to edit them :-(

Al


_______________________________________________
http://www.vtiger.com/
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: vt7: How to update field from Javascript

Susruthan Seran

I hope this will help you.

$('input[data-name="svc_charges"]').parents().find('.currencyValue').html("test");

Replace the test  with your value to show. I'm not much familiar with Detail_js but will solve your problem I hope.


On 01/20/2017 09:11 PM, Alan Lord wrote:
On 20/01/17 15:19, Susruthan Seran wrote:
Try this..

jQuery('input[data-name="svc_charges"]').attr('data-displayvalue',100);

It's getting somewhere...

In firebug that element now looks like:

<input class="fieldBasicData" data-name="svc_charges" data-type="currency" data-displayvalue="2264.177655529488" data-value="0.00" type="hidden">

But this has not updated the value visible to the end-user. This is in the two nested <span> above the input tag...

I would have assumed that there would be some kind of API for this kind of thing in the Detail_js class or similar but I've been hunting around the code and can't find anything.

And picklists are just a nightmare... They really do seem to be empty until you click the pencil icon to edit them :-(

Al


_______________________________________________
http://www.vtiger.com/


_______________________________________________
http://www.vtiger.com/
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: vt7: How to update field from Javascript

Alan Lord (News)
Thanks for the follow up.

I've now got it working but it is a big of a "dogs dinner" frankly.

First I need to grab the container (td) for the field or your suggestion
of using .parents() means I end up updating *every* currency field on
the page ;-)

> var svcChargeContainerId = '#'+moduleName+'_detailView_fieldValue_svc_charges';
> var svcChargeContainer = jQuery(svcChargeContainerId);

Then, once I've done the calculations I update the value in three places:

> svcChargeContainer.find('span.currencyValue').html(svcCharge);
> svcChargeContainer.find('input[data-name="svc_charges"]').attr('data-displayvalue', svcCharge);
> svcChargeContainer.find('input[data-name="svc_charges"]').data('value', svcCharge); // This one doesn't work...

It would be very helpful, for everyone if there was an API in the main
Detail and Edit view Javascript classes to support dynamic updating of
fields.

Now I need to trigger a save event on the Service Charge field and then
work out how to do the same thing in Edit View.

Then, the next thing I have to do is to try and sort out the picklist
problems... See thread "Re: Q. on vt7 Detail/Summary view picklists"

Thanks for helping.

Alan


On 20/01/17 18:08, Susruthan Seran wrote:

> I hope this will help you.
>
> $('input[data-name="svc_charges"]').parents().find('.currencyValue').html("test");
>
> Replace the *test  *with your value to show. I'm not much familiar with
> Detail_js but will solve your problem I hope.
>
>
> On 01/20/2017 09:11 PM, Alan Lord wrote:
>> On 20/01/17 15:19, Susruthan Seran wrote:
>>> Try this..
>>>
>>> jQuery('input[data-name="svc_charges"]').attr('data-displayvalue',100);
>>
>> It's getting somewhere...
>>
>> In firebug that element now looks like:
>>
>>> <input class="fieldBasicData" data-name="svc_charges"
>>> data-type="currency" data-displayvalue="2264.177655529488"
>>> data-value="0.00" type="hidden">
>>
>> But this has not updated the value visible to the end-user. This is in
>> the two nested <span> above the input tag...
>>
>> I would have assumed that there would be some kind of API for this
>> kind of thing in the Detail_js class or similar but I've been hunting
>> around the code and can't find anything.
>>
>> And picklists are just a nightmare... They really do seem to be empty
>> until you click the pencil icon to edit them :-(
>>
>> Al
>>
>>
>> _______________________________________________
>> http://www.vtiger.com/
>
>
>
> _______________________________________________
> http://www.vtiger.com/
>


_______________________________________________
http://www.vtiger.com/
Loading...