This.wrapper.find return error

// Copyright © 2015, Frappe Technologies and contributors
// For license information, please see license.txt

cur_frm.add_fetch(“course”, “course_code”, “course_code”);
cur_frm.add_fetch(‘fee_structure’, ‘total_amount’, ‘amount’);

frappe.ui.form.on(“Program”, “refresh”, function(frm) {
if(!frm.doc.islocal) {
frm.add_custom_button(
(“Student Applicant”), function() {
frappe.route_options = {
program: frm.doc.name
}
frappe.set_route(“List”, “Student Applicant”);
});

	frm.add_custom_button(__("Program Enrollment"), function() {
		frappe.route_options = {
			program: frm.doc.name
		}
		frappe.set_route("List", "Program Enrollment");
	});
	
	frm.add_custom_button(__("Student Group"), function() {
		frappe.route_options = {
			program: frm.doc.name
		}
		frappe.set_route("List", "Student Group");
	});
	
	frm.add_custom_button(__("Fee Structure"), function() {
		frappe.route_options = {
			program: frm.doc.name
		}
		frappe.set_route("List", "Fee Structure");
	});
	
	frm.add_custom_button(__("Fees"), function() {
		frappe.route_options = {
			program: frm.doc.name
		}
		frappe.set_route("List", "Fees");
	});
}

});

this.wrapper.find(".primary-action").click(function() {
console.log(“hi”);
});

i want to get print hi in cosole but i get error

Uncaught TypeError: Cannot read property ‘find’ of undefined(…)

@shahid_khan021,

In form you can set the primary action button click event using set_primary_action.

e.g.

frm.page.set_primary_action(label, function() {
console.log(“hi”)
})

but it will override the primary button action and you will need to write code for form save, Can you please share the usecase ?

Thanks,
Makarand

1 Like

thanks for the replay

my use case is i have a button in website

when i click on that button i want to show in console

or to generate a pdf file

html file is

{% extends “templates/web.html” %}

{% block content %}

<div class="row">
	<div class="">
		<h1>Details of the Program {{ doc.name }}</h1>
	</div>
	<div class="col-md-3">
		{% if doc.image -%}
			<img itemprop="brand" src="{{ doc.image }}" class="program-logo col-md-12"
				alt="{{ doc.program_name }}" title="{{ doc.program_name }}" />
		{%- endif %}
	</div>
	<p></p>
	<div class="col-md-9">
	    <section class="col-md-12" id="pgm">
			<label>Name of programs:</label><h2 id="pgmName">{{ doc.program_name }}</h2>
			<label>Programm abbrevation</label><p id="pgmAbbr">{{ doc.program_abbreviation }}</p>
			<label>programme code</label><p id="pgmCode">{{ doc.program_code }}</p>
			<label>Programme department <p id="pgmDepartment">{{ doc.department  }}</p>	
			<p>Courses Offered in this program : </p>  {% for c in courses %} <p id ="pgmCourse">{{ c.course }} </p>{% endfor %}
			<p>Total Fees For This Program: </p>  {% for c in fees %} <p id="pgmAmount">{{ c.amount }} </p>{% endfor %}
		</section>
		<button class="btn-download-pdf btn-primary pull-left" id="download" data-field="program">Download Pdf</button>
	</div>
</div>

{% endblock %}

For webview set_primary_action will not work you will need to write the javascript in script tag in html file itself.

Please check the https://github.com/frappe/frappe/blob/develop/frappe/www/feedback.html#L80 for example.

@makarand_b Thanks again it solved my half problem

thanks

can you please help me with creating pdf

@makarand_b

can i get the doctype form this script

like this

frappe.msgprint(__(this.frm.doc.doctype));

now i get

Cannot read property ‘doc’ of undefined

@shahid_khan021,

it will only work on Form view as you are working on webview this.frm.doc will not work

ok

thanks

i want to execute this code in the script

var w = window.open(
frappe.urllib.get_full_url("/api/method/frappe.utils.print_format.download_pdf?"
+“doctype=”+encodeURIComponent(me.frm.doc.doctype)
+"&name="+encodeURIComponent(me.frm.doc.name)
+"&format="+me.selected_format()
+"&no_letterhead="+(me.with_letterhead() ? “0” : “1”)
+(me.lang_code ? ("&_lang="+me.lang_code) : “”)));
if(!w) {
msgprint(__(“Please enable pop-ups”)); return;
}

is there any way to do that