unable to change the input background based on condition

change background color based on value html css
html conditional font color
how to dynamically change text color based on a background color css
change html table cell color depending on its value javascript
javascript change input text color
php change text color based on value
css background-color
change row color based on cell value jquery

here below is my JSON data

data = {
    name: 'paul',
    author: '',
    country: '',
    id: 7465
};

here by using the above data, I am displaying the input and label

 <label class="inline-label" for="{{data.name}}">{{data.name}}</label>

for input

<input id="{{data.name}}" type="{{data.details.type}}" style=" border-radius:0;" class="form-control error">

here my issue is

  1. I unable to display the input background color based on condition when the input value is empty only for selected one I have other input also it is based on other than I don't want to change

below is the code I have tried

if (data['author'] === '') {
    $('.error').css('background-color', '#fff');
    $('.error')
        .filter(function() {
            return $.trim(this.value) === '';
        })
        .css('border-bottom:', '1px solid #FF0000 !important');
} else {
    $('.error').css({ 'background-color': 'green' });
}

Try this input background color will be red if the name is falsy like empty string

<input type="text" [(ngModel)]="name" [ngStyle]="{'background-color': !name ?'#f00' : '#fff'}" />

Check author proprty

<input type="text" [(ngModel)]="data.author" [ngStyle]="{'background-color': !data.author ?'#f00' : '#fff'}" />

I will recommend to use angular form you can easy set the style of invalid inputs and don't use jquery

stackblitz

Functions: New Essays in the Philosophy of Psychology and Biology, Specifications of this sort concerning background conditions of operation and Cummins systems cannot be said to fail or malfunction as such, but they do have to is a set of responses to possible, not merely actual, inputs and conditions. A chunk of matter, depending on what are considered its 120 Ruth Garrett Millikan. Create a Conditional Formatting Rule. Click Conditional Formatting on the toolbar to display the Conditional Formatting window. Click Add New Rule to create a new, blank conditional formatting rule. Set the Conditions for the Rule. Click <set condition> to display the Set Condition window.

you can use something like this which does not include jquery

.white-background{
background-color
}

`<input id="{{data.name}}" [class.white-background]="!data.author" type="`{{data.details.type}}" style=" border-radius:0;" class="form-control error">

Change Text And Background Color Of Field Based On Field Value , It seems the best way to do this is change the CSS style of TextField when 10 is entered in color of 10 to change immediately to red (and if possible change the background color of the text field). Unfortunately I can't get this to work. Here is the input code: <input type="text" class="cbFormTextField"  How can I change the background colour of a div depending on it's containing <p> tag value/number when it has been generated? I have attached my code so far of the lottery generator. I just need the red background colour to change depending on the number result, like so:

Im not sure if this is what you are looking for, but you can change the background color of the input field based in some condition like this:

StackBlitz example: Change background based on condition

HTML file:

<label class="inline-label" for="{{data.name}}">{{data.name}}</label>

<input [(ngModel)]="input" name="input" type="text" id="{{data.name}}" [class.inputColor]="input">

TS file:

export class AppComponent  {
  name = 'Angular';

  input;

   data = {
    "name":'paul',
    "author":'',
    "country":'',
    "id":7465 ,
  }
}

CSS file:

.inputColor {
  background-color: blue;
  caret-color: white;
  color: white;
}

In this case the background color changes to blue and the letters to white when the input field is not empty.

To your second question, how to check if in a pair-value object the value field is empty you can do the following:

  object = {
    key: 'A',
    value: ''
  }

  isValueEmpty(object) {
    if (!object.value) return true;
    else return false;
  }

Pattern Recognition and Image Analysis: Third International , For outdoor scenes, illumination conditions, usually, change significantly during or consistent with current scene condition, the detection cannot result reliable. using current frame and previous background information; it is used as input of a a set of heuristics have been added to the plain background based approach​. I am having a tough time with this javascript code to change the background color of a text input if the input is empty. I would expect the textbox to come out yellow at the beginning. Note: You were checking value and setting color to value which is not allowed, that's why it was giving you errors. try like the above.

You can use Angular's ngClass binding to achieve this.

Data sample (.ts Service file returning Observable data):

  public items = [
    { "name":'paul', "author":'  ', "country":'', "id":7465 },
    { "name":'Jibin', "author":'JQuery', "country":'', "id":7466 }
  ];

Controller sample (.ts file to map another flag field):

import 'rxjs/add/operator/map';

public items = [];
private unsubData = new Subject<void>();

ngOnInit() {
    this.service.dataUpdated
    .takeUntil(this.unsubData)
    .map((data: any) => {
      data.forEach(element => {
        element.flgEmpty = (element['author'].trim() === '') ? true : false;
      });
      return data;
    })
    .subscribe((data: any) => {
      console.log(data);
      this.items = data;
    });
}

ngOnDestroy() {
    this.unsubData.next();
    this.unsubData.complete();
}

HTML sample (.html file):

<div *ngFor="let item of items">
  <label class="inline-label" for="{{item.name}}">{{item.name}}</label>
  <input id="{{item.name}}" type="text" [ngClass]="[item.flgEmpty ? 'form-control error' : 'form-control success']">
</div>

CSS sample (.css file):

.form-control { border-radius:0;}
.error {border-bottom: 1px solid #FF0000;}
.success {background-color: green;}

In excel, cannot figure out why background color for a cell will not , Did you check for conditional formatting? It is harder to change. Not sure where it is at in Excel 2007, but the mac version has it under: Format => Conditional  .colorA {background-color: red} .colorB {background-color: green} That answers your question based on your code. A better practice, imo, would be to put a statusClass property on your row2 object model.

Use CSS to change the style of each row depending on the content , Display and style elements depending on their value background:lightgrey a conditional template that will display a different content depending on rows be a color based on the color column and I can not get it to work. When the background of an element becomes too light, it can get easily lost against a white background. We might have a button and not even notice it. To provide a better UI on really light colors, we can set a border based on the very same background color, only darker.

Sharing Data and Models in Software Engineering, Evaluation bias: This chapter has focused on background knowledge specific to of background knowledge, which cannot be captured by the queries used in this study. These new input values satisfied the path conditions required to make the is based on data swapping where each value in a data set is replaced by  Change the background color of cells based on value (dynamically) - The background color will change automatically when the cell value changes. Change a cell's color based on its current value (statically) - Once set, the background color will not change no matter how the cell's value changes .

background-color, The background-color CSS property sets the background color of an element. enough that people experiencing low vision conditions will be able to removing the transparent keyword, this doesn't change anything as it  Fill a cell with color based on a condition. Before learning to conditionally format cells with color, here is how you can add color to any cell in Excel. Cell static format for colors. You can change the color of cells by going into the formatting of the cell and then go into the Fill section and then select the intended color to fill the cell.

Comments
  • are you use angular form like reactive form or template form ??
  • i am not using those as this has already developed with out using those thats why
  • I would suggest you to maybe set certain classes with styles that you expect when eg. author property is empty or not. Then instead of jQuery use it in HTML like <input [class]="someCondition ? 'class1':'class2'">
  • You can easily target input validation state like invalid input , touched by css only @Jibin
  • i tried the [ngStyle] approach but didnt worked
  • could u tell me how can i check whether a key is having value or not i mean empty
  • do you mean like this data.author @Jibin ?
  • I have updated the answer for checking author @Jibin
  • yeah what i did was Object.keys(data).map(k => data[k]) this is retrieving keys now if i can check data['author']=='' using loops then i can find a solution i think so here i need to check whether data['author'] is empty or not
  • I have update the stackbliz like sorry was linked to wrong url can you check now @Jibin
  • But this is not working ? & i already have some other [(ngModel)]