Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
ysapiyev
Responsive Resident
Responsive Resident

Trouble with adding checkbox

Hi everyone,

 

I wanted to add checkbox and tried this code:

svg.selectAll("foreignObject")
        .data(nodes)
        .enter().append("foreignObject")
        .attr('x' , o.x)
        .attr('y',  o.y)
        .attr('width', 50)
        .attr('height', 20)
        .append("xhtml:body")
        .html("<form><input type=checkbox id=check></input></form>")
     .on("click", function(d, i){            console.log(svg.select("#check").node().checked) 
            }) ;

How it can be added using "input"?

 

 

9 REPLIES 9
v-viig
Community Champion
Community Champion

Hi @ysapiyev

 

At first, you should include the second body tag since iframe already has it.

The input tag can be added by using d3.append method.

 

Ignat Vilesov,

Software Engineer

 

Microsoft Power BI Custom Visuals

pbicvsupport@microsoft.com

 

 

ysapiyev
Responsive Resident
Responsive Resident

@v-viig

 

Can you give an exaple, how it will look like? 

v-viig
Community Champion
Community Champion

 

You might use something like this code snippet:

 

d3.select(Your_Root_Element)
    .append("input")
    .attr({
        type: "checkbox"
    });

 

Ignat Vilesov,

Software Engineer

 

Microsoft Power BI Custom Visuals

pbicvsupport@microsoft.com

ysapiyev
Responsive Resident
Responsive Resident

@v-viig

 

I tried something like this:

 

let input1 = this.svg.append("input")
                    .attr({
                        type: "checkbox",
                        x: 200,
                        y: 50
                    });

However, nothing is shown. What can be wrong?

v-viig
Community Champion
Community Champion

Does this.svg contain an svg element?

Checkbox can be used only in HTML elements such as div, table, footer, etc.

 

Ignat Vilesov,

Software Engineer

 

Microsoft Power BI Custom Visuals

pbicvsupport@microsoft.com

ysapiyev
Responsive Resident
Responsive Resident

@v-viig,

 

So, as I understood, I should add div to svg, then add to it checkbox?

 

let checkbox_d = d3.select("div")
.append("input")
.attr(type: "checkbox");

Is it correct?

 

 

v-viig
Community Champion
Community Champion

You should add a div container to the root element.

After that you should include input element and svg element into this div container.

 

SVG element supports the only SVG elements.

 

Ignat Vilesov,

Software Engineer

 

Microsoft Power BI Custom Visuals

pbicvsupport@microsoft.com

ysapiyev
Responsive Resident
Responsive Resident

@v-viig,

 

So it will look like that?

 

let check= d3.select('body')
.append('div')
.append('input')
.type('checkbox')
let svg = d3.select(div)
.append('svg')

v-viig
Community Champion
Community Champion

Yes, that's correct.

 

Ignat Vilesov,

Software Engineer

 

Microsoft Power BI Custom Visuals

pbicvsupport@microsoft.com

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

Find out what's new and trending in the Fabric community.

July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.