I can't put a CSS class on a template - css

I'm reading a book about Angular 2 and one of the chapters is about Forms. I'm using Semantic UI Framework and when I put a class, specify the "error" class the div is disappear. Is very very strange I don't know what happened. I have to mention what works perfectly if I replace "error" class with another like "negative" for instead.
import { Component } from '#angular/core';
import {
FormBuilder,
FormGroup,
Validators,
AbstractControl,
FormControl
} from '#angular/forms';
#Component({
selector: 'demo-form-sku-builder',
template: `
<div class="ui raised segment">
<h2 class="ui header">Demo Form: Sku with Builder</h2>
<form [formGroup]="myForm"
(ngSubmit)="onSubmit(myForm.value)"
class="ui form">
<div class="field"
[class.error]="!sku.valid && sku.touched">
<label for="skuInput">SKU</label>
<input type="text"
id="skuInput"
placeholder="SKU"
[formControl]="myForm.controls['sku']">
<div *ngIf="!sku.valid"
class="ui error message">SKU is invalid</div>
<div *ngIf="!sku.hasError('required')"
class="ui error message">SKU is required</div>
</div>
<button type="submit" class="ui button">Submit</button>
</form>
</div>
`
})
export class DemoFormSkuBuilder {
myForm: FormGroup;
sku: AbstractControl;
constructor(fb: FormBuilder) {
this.myForm = fb.group({
'sku': ['', Validators.required]
});
this.sku = this.myForm.controls['sku'];
}
onSubmit(value: string): void {
console.log('you submitted value: ', value);
}
}

Is this if statement backwards?
<div *ngIf="!sku.hasError('required')"
class="ui error message">SKU is required</div>
Shouldn't it be:
<div *ngIf="sku.hasError('required')"
class="ui error message">SKU is required</div>
Without the not operator?

Use below code instead of [class.error]="!sku.valid && sku.touched"
<div class="field" [ngClass]="{ 'error' : !sku.valid && sku.touched}">
For more detail
Another way of doing is
import { Component } from '#angular/core';
import {
FormBuilder,
FormGroup,
Validators,
AbstractControl,
FormControl
} from '#angular/forms';
#Component({
selector: 'demo-form-sku-builder',
template: `
<div class="ui raised segment">
<h2 class="ui header">Demo Form: Sku with Builder</h2>
<form #myForm=ngForm
(submit)="onSubmit(myForm.value)"
class="ui form">
<div class="field"
[ngClass]="{ 'error' : !sku.valid && sku.touched}">
<label for="skuInput">SKU</label>
<input type="text"
id="skuInput"
placeholder="SKU"
name='sku'
#sku='ngModel' ngModel
required>
<div *ngIf="!sku.valid"
class="ui error message">SKU is invalid</div>
<div *ngIf="!sku.touched && !sku.errors?.required"
class="ui error message">SKU is required</div>
</div>
<button type="submit" class="ui button">Submit</button>
</form>
</div>
`
})
export class DemoFormSkuBuilder {
constructor() {
}
onSubmit(value: string): void {
console.log('you submitted value: ', value);
}
}

Fixed. by default, semantic UI hides these unless the whole form is in the same state. You can create an another css called styles.css for example and use this:
.ui.form .error.message,
.ui.form .success.message,
.ui.form .warning.message {
display: block;
}

Related

(SOLVED)(Next.js 13 + Next-i18next): Translations does not work on specific page when deployed to AWS Amplify

When i run locally (even with yarn start in prod mode), my translations work correctly. However, after i deploy my project to AWS Amplify, this specific /dashboard page is not working the translations (no error messages at all in console.log, nothing).
I have the following structure:
import { serverSideTranslations } from 'next-i18next/serverSideTranslations'
import { UserHome } from '~/templates'
export default function Dashboard() {
return <UserHome />
}
export async function getServerSideProps({ locale }: { locale: string }) {
const res = await serverSideTranslations(locale, ['common'])
return {
props: {
...res
}
}
}
This leads to UserHome template. Now the following:
import { useTranslation } from 'next-i18next'
import Image from 'next/image'
import { PageHeader, TableCampaign } from '~/components'
import { tableData } from '~/components/TableCampaign/mock'
import Base from '../Base'
import styles from './user-home.module.css'
const UserHome = () => {
const { t } = useTranslation('common')
return (
<Base>
<PageHeader image="/img/computer.svg" title={t('tableCampaign.title')}>
<div className={styles.header__legends}>
<div className={styles.header__infos}>
<div className={styles.header__legend}>
<div
className={`${styles.header__circle} ${styles.header__circle__success}`}
></div>
<p className={styles.header__state}>
{t('tableCampaign.active')}
</p>
</div>
<div className={`${styles.header__legend} mt-2`}>
<Image
src="/icon/eye.svg"
alt="Eye icon"
className="mr-2"
width={24}
height={24}
/>
<p className={styles.header__state}>{t('tableCampaign.view')}</p>
</div>
</div>
<div className={`${styles.header__infos} mx-6`}>
<div className={styles.header__legend}>
<div
className={`${styles.header__circle} ${styles.header__circle__warning}`}
></div>
<p className={styles.header__state}>
{t('tableCampaign.pending')}
</p>
</div>
<div className={`${styles.header__legend} mt-2`}>
<Image
src="/icon/edit.svg"
alt="Pen icon"
className="mr-2"
width={24}
height={24}
/>
<p className={styles.header__state}>{t('tableCampaign.edit')}</p>
</div>
</div>
<div className={styles.header__infos}>
<div className={styles.header__legend}>
<div
className={`${styles.header__circle} ${styles.header__circle__danger}`}
></div>
<p className={styles.header__state}>
{t('tableCampaign.finished')}
</p>
</div>
<div className={`${styles.header__legend} mt-2`}>
<Image
src="/icon/download.svg"
alt="Download icon"
className="mr-2"
width={24}
height={24}
/>
<p className={styles.header__state}>
{t('tableCampaign.download')}
</p>
</div>
</div>
</div>
</PageHeader>
<TableCampaign tableList={tableData} />
</Base>
)
}
export default UserHome
The translations of UserHome and Base component, and the components inside Base are not working. The other pages are working correctly. Do you guys have any idea?

class active CSS issue in angular

I have separate component of a tile in which i show all the list of data so when i click the tile it should show active class CSS in particular tile but now where ever i click it shows active class in all tiles.
div class="container-fluid" style="margin-top: 12px" *ngIf="!loading">
<div class="container-fluid " *ngIf="!done">
<adm-tile
[heading]='heading'
[orderno]='stock.id'
[time]='stock.created_at'
[category]='stock.request_category.name'
[status_type]='getStatus(stock.status)'
[name]='stock.requester.first_name'
[branch]='stock.to_department.name'
[date]='stock.delivery_date'
[priority]='stock.priority'
[index_no] = 'i'
[data]= 'stock'
[title]="'Requested To'"
[title1] = "'From'"
(selected)="onButton06($event)"
*ngFor="let stock of stock_list ; let i = index" ></adm-tile>
<div class="wrapper-card __list-card --small-card" style="margin-top:-5px" (click)="button01()" [class.active-border-selection]="index_no === selectedIndex1">
<div class="media">
<div class="media-body">
<div class="rowa split" style="position: relative">
<div class="col-6" style="position: relative">
<div >
<div style="height: 19px;overflow: hidden !important;">
<label class=" bold2">{{heading}}</label><span class="bold2">:#{{orderno}} </span>
<span class="bold2 desktop"> - {{your_date | timeAgo}}</span>
</div>
<div style="height: 22px">
<label class="bold3 ">{{category}}</label>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
button01() {
this.selectedIndex1 = this.index_no;
}
Based on your question for only one button or card to be active at one time, check below code. You need to set active in the parent component only not in child as all child are independent components.
Parent Component
import { Component } from '#angular/core';
#Component({
selector: 'payroll-search',
template: `
<div *ngFor="let stock of stock_list ; let i = index" >
<hr-files-search
style="position: relative; display:block"
(sendIndex)="getIndex($event)"
[class.active-border-selection]="i == selectedIndex"
[index_no] = 'i'
></hr-files-search>
</div>
`
})
export class PayrollSearchComponent {
stock_list = [1,2,3,4,4,5];
public selectedIndex: number;
public getIndex(event) {
this.selectedIndex = event;
}
}
Child component
import { Component, Input , OnInit, Output, EventEmitter } from '#angular/core';
#Component({
selector: 'hr-files-search',
template: `
<div class="card" (click)="button01(index_no)">
<div class="card-content">
<h6>hello</h6>
</div>
</div>
`
})
export class HrFilesSearchComponent implements OnInit {
#Input() index_no: any;
#Output() sendIndex = new EventEmitter();
ngOnInit() {
}
selectedIndex1;
button01(index) {
this.sendIndex.emit(index);
}
}
Here is the stackblitz solution.

Multiple stylesheets issue using React

I am new to react, I have an issue on how to maintain stylesheets in react.
For Eg: If I have box structures in different components with the same class names which are import to Page-A & Page-B, I maintained different stylesheets & appended those to their respective pages. If I change the style properties for Page-B in respective stylesheet using the same class name, changes are reflecting in both the Page-A & Page-B pages, which is suppose to reflect in Page-B only. Please help to solve this.
Page-A<div class="wrapper">Headline<div>.wrapper{background:red; width:200px; height:200px;}
Page-B<div class="wrapper">Headline<div>.wrapper{background:black; width:400px; height:400px;}
import React, { Component } from 'react';
import NavbarafterLogin from './NavigationBar/navbarafterlogin';
import '../../Css/afterlogins.css';
class Home extends Component {
render() {
return (
<div class="col-sm-12 col-xs-12">
<NavbarafterLogin/>
<div class="body-wrapper">
<div class="container">
<ViewProfile/>
</div>
</div>
</div>
)
}
}
export default Home;
import React, { Component } from 'react'
import NavbarBeforeLogin from './NavigationBar/navbarbeforelogin';
import '../../Css/beforelogins.css';
class Index extends Component {
render() {
return (
<div class="col-sm-12 col-xs-12">
<NavbarBeforeLogin />
<div class="body-wrapper clearfix">
<div class="col-sm-12 col-xs-12">
<div class="banner-sec">
<div class="jumbotron">
<div class="container">
<h1>Submit <strong>Profile</strong></h1>
</div>
</div>
</div>
</div>
</div>
</div>
)
}
}
export default Index;

How to override a css class in style component

In Search.tsx:
import { SearchInput } from Search.styles.ts
<SearchInput
onChange={handleChange}
value={values["searchValue"]}
placeholder="Search"
type="text"
name="searchValue"
/>
Output html:
<div class="1">
<div class="2">
<div class="3">
<span class="InputWrapper">
<input placeholder="Search" name="searchValue" class="Input input normalVariant" formnovalidate="" type="text" value="" >
</span>
</div>
</div>
</div>
In Search.styles.ts:
import * as Toolkit from "#some_repo/toolkit";
export const SearchInput = styled(Toolkit.Input)`
InputWrapper: 100%
`
I want set InputWrapper: width 100%, what is the correct way to do it?
It works just like css.
import * as Toolkit from "#some_repo/toolkit";
export const SearchInput = styled(Toolkit.Input)`
.InputWrapper {
width: 100%;
};
import * as Toolkit from "#some_repo/toolkit";
export const SearchInput = styled(Toolkit.Input)`
width: 100%;
`

How to change background color of input once value is selected using AngularJS?

I have selected user from search in Js function currently input field is readOnly , So once we have value from selectedOwner i want to change input field background color to white because user don't want to see gray color that is coming from readOnly directive ? Is there way to implement this kind of requirement ?
main.html
<div class="form-group col-md-6">
<div class="col-md-6">
<label class="control-label required" for="rcsaOwner">RCSA
Owner :</label>
</div>
<div class="col-md-6">
<input type="text" class="form-control" id="rcsaOwner" required ng-class="{'background1': color.back}"
ng-model="riskAssessmentDTO.rcsaOwnerWorker" name="rcsaOwnerWorker"
ng-click="openRcsaOwner()" ng-model-options="{updateOn: 'blur'}" ng-readOnly="true"/>
<p class="text-danger"
ng-show="addAssessment.rcsaOwnerWorker.$touched && addAssessment.rcsaOwner.$error.required">RCSA
Owner is required</p>
</div>
</div>
mainCtrl.Js
$scope.selectedOwner = function (selectedOwner, workerKey) {
this.$parent.$parent.rcsaOwnerModal.close();
$scope.riskAssessmentDTO.rcsaOwnerWorkerKey = workerKey;
$scope.riskAssessmentDTO.rcsaOwnerWorker = selectedOwner;
$scope.color = { back: true};
};
main.css
.background1 {
background-color: #eeee12;
color: red;
}

Resources