custom-cards / button-card

❇️ Lovelace button-card for home assistant
MIT License
1.83k stars 227 forks source link

Inline SVG as background image doenst seem to work after initial page load #825

Closed skykingjwc closed 5 months ago

skykingjwc commented 5 months ago

Checklist

Describe the bug When attempting to use a javascript template to set an inline SVG as a background image, the proper image is shown on the initial page load, however when changing states after page load, the template appears to not work and the background image is not updated. I have tried multiple variations of double and single quotes as well as template literal. I am 100% sure the state change is being picked up because I put an alert() in the javascript template for testing and attached a debugger. I also tried triggers_update: all just to be sure. In the example below, if the value of the input_select is 'red' on page load the svg will be shown. If I then update the value to something else, the greentest.png will be show. Changing the state back to 'red' results in no change to the background image. There are no errors which appear in the console dev tools.

Version of the card Version: 4.11

To Reproduce This is the configuration I used:

      - background-image: >
          [[[
            if (states['input_text.lcars_alert_status'].state == 'red')
            {
              return `url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 115.5 99.8' ><polygon points='67.2,98.8 114.3,17.6 104.3,1 11.3,1 1.2,17.6 47.6,98.8' style='fill: none; stroke: red; stroke-miterlimit: 10; stroke-width: 2px;'/></svg>");`
            }
            else
            {
              return 'url("/local/images/testimages/greentest.png")'
            }
          ]]]

Screenshots No screenshots needed

Expected behavior Background image should change when state of input_text changes

Desktop (please complete the following information):

Smartphone (please complete the following information): None

Additional context I imagine his has something to do with the inline SVG as other image types seem to work fine.

RomRider commented 5 months ago

Try to remove the ; from the end of the svg string.

skykingjwc commented 5 months ago

Seems to have worked. Could have sworn I tried that. Thanks for the assist.