Target Angular mat-checkbox nested dinamically created element - css

I have a series of checkboxes that I create using mat-checkbox, with it respective Select all one. What I need is to target that specific (and first) checkbox and hide it. Only the checkbox, not the label or any other element within mat-checkbox.
My checkboxes are default ones, so an example would be something like this:
Demo
After the elements are created, you have a structure that looks like this:
<mat-checkbox _ngcontent-ici-c72="" class="mat-checkbox mat-accent ng-valid ng-dirty ng-touched"
ng-reflect-model="false" ng-reflect-options="[object Object]" d="mat-checkbox-1">
<label class="mat-checkbox-layout" for="mat-checkbox-1-input">
<div class="mat-checkbox-inner-container">
<input type="checkbox" class="mat-checkbox-input cdk-visually-hidden" id="mat-checkbox-1-input" tabindex="0"
aria-checked="false">
<div matripple="" class="mat-ripple mat-checkbox-ripple mat-focus-indicator"
ng-reflect-trigger="[object HTMLLabelElement]" ng-reflect-disabled="false" ng-reflect-radius="20"
ng-reflect-centered="true" ng-reflect-animation="[object Object]">
<div class="mat-ripple-element mat-checkbox-persistent-ripple"></div>
</div>
<div class="mat-checkbox-frame"></div>
<div class="mat-checkbox-background"><svg version="1.1" focusable="false" viewBox="0 0 24 24"
xml:space="preserve" class="mat-checkbox-checkmark">
<path fill="none" stroke="white" d="M4.1,12.7 9,17.6 20.3,6.3" class="mat-checkbox-checkmark-path"></path>
</svg>
<div class="mat-checkbox-mixedmark"></div>
</div>
</div>
<span class="mat-checkbox-label"><span style="display: none;">
</span>Select All</span>
</label>
</mat-checkbox>
Everything created after the page is loaded by Angular, except the span element that contains Select All.
I need to target only the first element that contains the class mat-checkbox-inner-container
So far, if I try via CSS, all elements with that class are hidden, i.e. all checkboxes, not only the first one.
I've also tried to create a class in my CSS and add it via TS, with no positive result. This is the snippet for that:
checkHider():void {
let elem = document.getElementsByClassName("mat-checkbox-inner-container")[0];
elem.classList.add("hider");
}

I was able to get the element inside the ngOnInit function, and it worked.
This is the snippet. Note that the position is only specific to my case.
let elem = document.getElementsByTagName('div')[6];
elem.setAttribute("style", "display: none");

Related

cdk drag and drop on images is not working

I want to drag an image from one div to another div. I tried creating two arrays containing src of images and looping through all the src thereby two lists will be displayed so that I'm able to drag and drop easily by creating a function (cdkDropListDropped)="drop($event)"
if (event.previousContainer === event.container) {
moveItemInArray(event.container.data, event.previousIndex, event.currentIndex);
} else {
transferArrayItem(event.previousContainer.data,
event.container.data,
event.previousIndex,
event.currentIndex);
}
}
but here I'm using only a single image and no array is being used. So, how can I drag and drop and I'm not aware of the function I should use for an image getting drop perfectly into another div.
html:
<div class="example1"
cdkDropList
id = "pic1"
[cdkDropListConnectedTo]="['pic2']"
style="background-color:red;"
>
<div cdkDrag class="example-box">
<img width="350px" height="250px" src="https://material.angular.io/assets/img/examples/shiba2.jpg" alt="Photo of a Shiba Inu">
</div>
</div>
<div class="example2"
cdkDropList
id = "pic2"
style="background-color:yellow;"
[cdkDropListConnectedTo]="['pic1']"
>
<div cdkDrag class="example-box">
</div>
</div>

Prevent checkbox Label to Toggle the checkBox

Here is my checkbox in angular and i want to prevent the default behaviour of it.
<mat-checkbox (change)="changeSelectionTo()" [(ngModel)]="isChangeRule">Name</mat-checkbox>
Here whenever i click on name label...the checkbox gets toggled which i do not want to..
How can i prevent this from toggling when click on label . I have tried all others post too but I could not come up with the solution . I can not use jQuery.
Based on #Mike S. comment:
<mat-checkbox (change)="changeSelectionTo()" [(ngModel)]="isChangeRule">
<span (click)="myCheck($event)">Name</span>
</mat-checkbox>
in your component typescript code:
myCheck(event) {
event.preventDefault();
//YOUR LOGIC
}
you need to add label after completing the <mat-checkbox> tag.
According to your design, you can add style to the <mat-label>
Replace your line of code with the below shown code:
<div layout=row>
<mat-checkbox (change)="changeSelectionTo()" [(ngModel)]="isChangeRule"></mat-checkbox>
<mat-label> Name </mat-lable>
</div>
above image is generated by below code
<div align="left" class="user-modified-rule">
<div layout="row">
<mat-checkbox (change)="changeSelectionTo()" [(ngModel)]="isChangeRule">
</mat-checkbox>
<mat-label>
<rule></rule>
</mat-label>
</div>
</div>
and css code
.user-modified-rule {
display: inline-block;
width : 48%;
}

(Fullcalendar 4 VueJs) Adding custom element inside Calendar Header

Please take a look at my approach and tell me is it a good/correct way to add a complex DOM element inside Fullcalendar header.
viewSkeletonRender(info){
this.$refs.fullCalendar.$el.querySelector('.fc-header-toolbar').insertAdjacentHTML('afterbegin', `
<div class="event_create-wrap">
<div class="event_create-btn">
<div class="event_create-btn-left">
Create
</div>
<div class="event_create-dropdown">
<button class="event_create-btn-dropdown" #click="eventDropdownClicked">
<svg width="20" height="20" viewBox="0 0 20 20" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M111 13.8822L3.62734 8.39658C3.23555 8.01742 3.23555 7.40432 3.62734 7.0292L4.5693 6.11762C4.96109 5.73846 5.59462 5.73846 5.98224 6.11762L10.0002 10.006L14.0181 6.11762C14.4099 5.73846 15.0434 5.73846 15.431 6.11762L16.373 7.0292C16.7648 7.40836 16.7648 8.02146 16.373 8.39658L10.7045 13.8822C10.3211 14.2614 9.68756 14.2614 9.29578 13.8822Z" fill="white"/>
</svg>
</button>
<div class="event_create-btn-dropdown-content" :class="{show: isEventListShown}">
1
2
3
</div>
</div>
</div>
</div>
`);
}
I am using "viewSkeletonRender" hook but i am not really sure that using "insertAdjacentHTML" is good, since i've used it first time.
I can't use AppendChild because i need to add so many html code there and it is difficult to create all html objects step by step (what if i need to add 100 html tags...) .
I can't use innerHtml because it will remove all what i have in fc-header-toolbar.
And as i understand i can't bind any VueJs props and methods to this HTML with this approach because i add this html as vanila Js.
Thank you for your advice.

Materilaize css breaking primeng rendering of input field. How do I fix this css?

I have the following code:
<div class="container" style="width:100%;">
<div class="ui-widget-header" style="padding:4px 10px;border-bottom: 0 none">
<i class="fa fa-search" style="margin:4px 4px 0 0"></i>
<input #gb type="text" pInputText size="50" placeholder="Global Filter">
</div>
<p-dataTable [value]="cars" [globalFilter]="gb">
<p-column field="vin" header="Vin"></p-column>
<p-column field="year" header="Year"></p-column>
<p-column field="brand" header="Brand"></p-column>
<p-column field="color" header="Color"></p-column>
</p-dataTable>
</div>
My component has:
cars = [{
'vin': 'von',
'year': '1990',
'brand': 'Audi',
'color': 'blue'
},{
'vin': 'another',
'year': '2050',
'brand': 'Honda',
'color': 'silver'
}
]
This should be fine, but the problem is I want to use primeng with materializecss. Is there a way I can make it so that for the input box, it does not use materializecss's styling and preserves what primeng already has? At this point, the search box looks messed up with the magnifying glass being above the input field and not inline.
Its supposed to look like this:
https://www.primefaces.org/primeng/#/datatable/filter
If materalizecss overrides same class that primeng uses, you could just load them in different order, first materalizecss then primeng css. This will ensure that primeng css will override same classes materalize defines.
Find out which class materalize overrides and try to work on that.
Edit
I think this plnkr provides an example of your problem
http://plnkr.co/edit/6ptJJw8z9fOgHAAfSv4u?p=preview
Here is how you can fix it
When I open developer tools and select the input box that I want to examine,
it shows me that materalize.css has a class as follows
As you can see here, this css class has highest priority and overrides primeng class. Also, it gives a hint that is :not(.browser-default) pseudoclass.
So if you give your input browser-default class, this rule won't apply.
Check this plnkr
http://plnkr.co/edit/hTa2yxNZJP2Z8p91tQ9t?p=preview
All I did is to add browser-default class to the input
<input #gb type="text" class="browser-default" pInputText size="50" placeholder="Global Filter">

Filtering click element event with matching css selector to an object

I've ran into a problem and can't seem to get the GTM to register the event specifically.
Here is how the HTML looks like for the element that I need to register when someone clicks on it.
<div class="targetDiv option option-hoverable">
<div class="shape">
<svg width="140" height="140" viewBox="0 0 140 140" xmlns="http://www.w3.org/2000/svg" xmlns:sketch="http://www.bohemiancoding.com/sketch/ns">
<title>Shape + Shape + Shape</title>
<desc>Created with Sketch.</desc>
<g transform="translate(0 0)" sketch:type="MSShapeGroup" fill="none">
<circle id="Shape" fill="#CFDF80" cx="40" cy="84.434" r="40"></circle>
<circle id="Shape" fill="#FDE9E8" cx="80" cy="40" r="40"></circle>
<circle fill="#E2506E" cx="100" cy="100" r="40"></circle>
</g>
</svg>
</div>
<h3>Product Title</h3>
<div class="actions">
<a class="button button-subtle button-toggle" data-colors="tender" data-toggled="Select" href="">Select</a>
</div>
</div>
I can't get the Click to register on the outter DIV click, it registers wither the button click or the click on shapes. I need it to register on the DIV with class targetDiv.
I'm getting correct Click triggers from other places, so listening isn't a problem.
Right now the trigger is set like this:
Trigger Type - Click - all elements
Trigger fires on some clicks.
And the conditions are:
Click Element -> matches CSS selector -> targetDiv
This
Click Element -> matches CSS selector -> targetDiv
wants to match a <targetDiv> element, which is not present in your html code.
Try writing a dot before the classname, since that is how you can write a css selector for a class:
Click Element -> matches CSS selector -> .targetDiv

Resources