Navigation überspringen

[Gelöst] adding javascript to custom field at dashboard

This support ticket is created vor 4 Jahre, 3 Monaten. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

Dieses Thema enthält 5 Antworten, hat 2 Stimmen.

Zuletzt aktualisiert von Minesh vor 4 Jahre, 3 Monaten.

Assistiert von: Minesh.

Author
Artikel
#1969101
Screenshot 2021-02-28 at 12.59.28 AM.png

Dear Sir/Madam,

I have a custom post with custom field, I want to build a button to generate a code to a custom field when creating a custom post from dashboard. is it possible to do?

Best regards,

Kelvin.

#1970323

Minesh
Unterstützer

Sprachen: Englisch (English )

Zeitzone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

I'm afraid that there is no such feature exists. You may have to write custom Javascript/jQuery code that could help you to achieve what you need. If you do not know how to do it, I suggest you to contact Javascript Pro who should help you on this custom requirement.

#1971625

Dear Minesh,

Understood, I may write my own javascript to do, could you tell me how Toolset define the element's name from the dashboard? Is there any standard naming from Toolset?

Best regards,

Kelvin.

#1971961

Minesh
Unterstützer

Sprachen: Englisch (English )

Zeitzone: Asia/Kolkata (GMT+05:30)

If you look at the page source or try to Inspect the specific field, you will be able to see the information about the rendered element (field).

More info:
=> versteckter Link

#1972179

Dear Minesh,

I know how to use the web inspector but I have no idea how Toolset name the element id, like

<div class="js-wpt-field-items">
			<div class="js-wpt-field-item wpt-field-item">
		<div id="post-textfield-7-1614689486-wrapper" class="form-item form-item-textfield wpt-form-item wpt-form-item-textfield">
<input type="text" id="post-textfield-7-1614689486" name="wpcf[score]" value="銀獎" class="wpt-form-textfield form-textfield textfield" data-wpt-type="textfield" data-wpt-id="wpcf-score" data-wpt-name="wpcf[score]"></div>
	</div>
</div>

the id post-textfield-7-1614689486 is being changed everytime, it can't be called by Javascript if I can't sure the name of the id.

Best regards,

Kelvin.

#1972249

Minesh
Unterstützer

Sprachen: Englisch (English )

Zeitzone: Asia/Kolkata (GMT+05:30)

Yes - that is true. You should not target the element ID but element name.

For example:

jQuery("input[name='wpcf[score]']").change(function(){
  /// your code
});

jQuery("select[name='wpcf[my-select-field-slug]']").change(function(){
  /// your code
});;