Quantcast
Channel: Active questions tagged javascript - Stack Overflow
Viewing all 142382 articles
Browse latest View live

Filter out all child elements from parent in Vanilla JavaScript

$
0
0

I am trying to query DOM in Vanilla JavaScript to filter out all elemnts containing the img tags from the parent node with class icon. Example:

After writing query it should return two elements <span> and <a>:

<span class="icon"><a href="#">link</a></span>
<a class="icon" href="#">link</a>

This should not return anything:

<span class="icon"><a href="#"><img src="asdf"></a></span>
<a class="icon" href="#"><img src="asdf"></a>

Using jQuery I can easily achieve this using:

jQuery('.icon').not(':has(img)')

I am finding it bit challenging to implement the same in Vanilla JavaScript.


Angular failed run [closed]

$
0
0

I'm trying to compile my Angular Application.

so at first, I tried to run npm start, it gives me these following errors.

See in link

And when I make any type of changes it works!

Do you have any idea what could cause the problem?

Thanks a lot.

Adding/removing class with D3

$
0
0

The following two questions have more to do with CSS than with D3.

let svg = d3.select('body')
            .append('svg');
svg.append('circle')
   .attr('cx', 100)
   .attr('cy', 100)
   .attr('r', 50)
   .attr('class', ball)
   .on('mouseenter', function() {
       d3.select(this)
         .classed('over', true);
   });
circle.ball {
    fill: blue;
}
circle.ball over {
    fill: yellow;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/5.7.0/d3.min.js"></script>

If in the code above I write

circle {
    fill: blue;
}

instead of

circle.ball {
    fill: blue;
}

then the circle is initially filled blue. Why is setting the class to blue not affecting the fill?

I'm aware of the :hover CSS option. In the following I'd like to effect a change using the mouseenter event and a class setting. When the event is triggered, an additional class over adjusts the fill. Why does inserting the additional class not affect the fill?

Specifically, is circle.ball over the right specification to say "applies only when the two classes ball and over are simultaneously present for a circle"?

(The symmetric case for mouse exit, along with setting .classed('over', false), is omitted.)

How to take screenshot of a div with JavaScript?

$
0
0

I am building something called the "HTML Quiz". It's completely ran on JavaScript and it's pretty cool.

At the end, a results box pops up that says "Your Results:" and it shows how much time they took, what percentage they got, and how many questions they got right out of 10. I would like to have a button that says "Capture results" and have it somehow take a screenshot or something of the div, and then just show the image captured on the page where they can right click and "Save image as."

I really would love to do this so they can share their results with others. I don't want them to "copy" the results because they can easily change that. If they change what it says in the image, oh well.

Does anyone know a way to do this or something similar?

getting undefined selected value from dropdown in react native

$
0
0

I am new to learn react native. I want to get selected value from dropdown in react-native.

my constructor

constructor(props){
      super(props);
      this.state = ({       
        PickerSelectedVal : ''
      })
}

in render

render(){
      <Dropdown                 
                label="Select"
                options={["Op1","Op2"]}                     
                selectedValue={this.state.PickerSelectedVal}
                onSelect={(obj)=>this.changedemo({obj})}
      />
}

in function

 changedemo= (ob)=>{
      this.setState({PickerSelectedVal : ob});
      alert("Selected country is : " +ob.PickerSelectedVal);
      console.log(this.state.PickerSelectedVal);
      if (this.state.PickerSelectedVal === 1) {
          alert("Selected value is : " +ob.PickerSelectedVal);
      } 
      if(this.state.PickerSelectedVal === 0) {
alert("Selected value is : " +ob.PickerSelectedVal);
      }

  }

I have tried many times. I want to get selected value from dropdown alert is also showing but it prints. Selected value is:undefined.

ng-controller doesn't work in Angular what should I do?

$
0
0

I am new in Angular and I am trying something very simple. It looks like ng-controller doesn't work, the word "Jon" has no appearance neither inside the input box, neither after "This is"

<head>

</head>
<body>
<div>
  <p class="bolt">Είσοδος</p>
  <pre></pre>

</div>
<div class="row" ng-app="admin" ng-controller="ctrl">
  &nbsp;
  &nbsp;
  <p>Εισάγετε αριθμό πινακίδας:</p>

  &nbsp;
  &nbsp;

 <input  type="text" ng-model="ida"> 
  This is: {{ida}}

</div>
<script>
var app = angular.module('admin', []);
app.controller('ctrl', function($scope) {
  $scope.ida = "Jon";

});
</script>
</body>
</html>```

(VueJs) I can't use methods in vuejs?

$
0
0

Hi I'm trying to make a website where I have a home and a "Brazil" component. I'm using vue router to switch between home and Brazil. In Brazil there is a calculator but I cant use the methods used in the script tag. The calculator should ask for a grade input and then calculate the Average of it when the user clickes on Average. The calculation is correct. The buttons don't work. Does annyone know what the problem is? Here is the code:

<template>

  <div>
    Brazil
    <h2>Grade-Calculator </h2>
    <div id="calculator">
      <ul>
        <li v-for="(g,idx) in grades" :key="idx">{{idx+1}}. Grade : {{g}}</li>
      </ul>
      <div>
        <label>New Grade: </label>
        <input type="text" v-model="newGrade" />
        <button v-on:click="addGrade()">Ok</button>
      </div>
      <br>
      <div>
        <button v-on:click="calcAvg()">Average</button>
        <p>Average: {{ sum }}</p>
      </div>
  </div>
  </div>
</template>

<script>
import Vue from 'vue'
export default {
  name: "Brazil",
  props: {}
};
new Vue({
    el: '#calculator',
    data: {
      grades: [],
      newGrade: 0,
      avg: 0
      //TEST
    },
    methods: {
      addGrade: function () {
        this.grades.push(this.newGrade)
        this.newGrade = 0
      },
      calcAvg: function () {
        let sum = 0;
        for (var i = 0; i < this.grades.length; i++) {
          let zahl = parseInt(this.grades[i]);
          sum = sum + zahl;
        }
        //calculate average and print it
        console.log(sum)
        console.log(this.grades.length)
        return sum / this.grades.length;
      }
    }
  })
</script>

why am I getting always "TypeError: callback is not a function"

$
0
0

Simple problem in React, I just want to make a simple callback to delay the loading of the data

function getSettings(callback) {
    getColors();
    callback();
  }

  useEffect(() => {
    getSettings().console.log(settings);
    // eslint-disable-next-line
  }, []);

and I get:

"TypeError: callback is not a function"

Amcharts 4 - Grid moving when adding value to the chart

$
0
0

I am creating a chart which can be controlled by a slider with a cursor. To do this, I first set the chart data with empty array.

I also set xAxis as dateAxis with min and max value so that all labels are displayed even if there is no data in chart.

When dragging the cursor, I add/remove items dynamically in data array. The problem here is that when adding second value of the chart, first chart line is drawn and grid move a bit (because of coordinates calculation?)

Do anyone knows how could I get rid of this display bug ? I cant use fixed categories for xAxis by the way, because it will require to add data on the chart from the beginning (I also tried to set an array "null" value as data provider, but there were some refresh bugs when adding/removing data)

Here is related chart https://gearworks.fr/samples/fct426/chart/ (try to drag blue cursor and see what happens when moving from 1970 to 1971)

Thank you

MongoDB - 2 Unique keys in Single Schema not allowed?

$
0
0

Trying to do this in mongoose:

const blogPost = new Schema({
  title: { type: String, unique: true },
  slug: { type: String, unique: true },
  //...
});

However, I get an error:

MongoError: E11000 duplicate key error collection: blog.articles index: slug_1 dup key: { : null }

Is this not allowed? I just want to make sure nobody creates a slug twice, and neither uses the same title twice.

Symfony form validation from an AJAX render

$
0
0

I'm new to symfony, I render forms throughout a JSON so whenever I click on an icon it shows different forms (to change firstname, lastname...). I return thoses forms as a JSON :

    public function profileSettings()
{
    $user = $this->getUser();

    // Formulaire d'informations concernant le compte

    $formAccountSettings = $this->createForm(AccountSettingsType::class, $user, [
        'userEmail' => $user->getEmail(),
        'userUsername' => $user->getUsername(),
    ]);

    // Formulaire d'informations personnel

    $formPersonnalSettings = $this->createForm(PersonnalSettingsType::class, $user, [
        'userFirstname' => $user->getFirstname(),
        'userLastname' => $user->getLastname(),
    ]);

    // Retour en format JSON des 3 requêtes sous tableau

    return $this->json(
        [
            'formAccountSettingsView' =>
                $this->render('user/_accountSettings.html.twig', [
                    'form' => $formAccountSettings->createView(),
                ]),

            'currentUser' => $user,

            'formPersonnalSettingsView' => $this->render('user/_accountSettings.html.twig', [
                'form' => $formPersonnalSettings->createView(),
            ]),
        ]
    );
}

Here is how I display this :

    $('#settings-user li').on('click', function (e) {
    $.ajax({
        type: 'GET',
        url: "/website-skeleton/public/index.php/json/profile",
        success: function (response) {
            if ($(e.target).hasClass('profile')) {
                $('.display').empty().append(
                    `
                           <p id="welcome">Bonjour, <em><strong>${response['currentUser']['username']}</strong></em> vous êtes enregistré sous le nom de <strong>${response['currentUser']['firstname']} ${response['currentUser']['lastname']}</strong>.
                               <br>
                               Votre adresse email est : <strong>${response['currentUser']['email']}</strong>.
                               <br>
                               Pour modifiez vos informations veuillez cliquez sur le menu de navigation.
                           </p>`);
            } else if ($(e.target).hasClass('security')) {
                $('.display').empty().append(response['formAccountSettingsView']['content']);
            } else if ($(e.target).hasClass('informations')) {
                $('.display').empty().append(response['formPersonnalSettingsView']['content'])
            }
        }
    })
});

The problem now is that I don't know how to handle thoses forms from another controller and validate it with the constraints I set on my entity User this is how I validate :

public function editCredentials(Request $request, UserPasswordEncoderInterface $encoder)
{
    $user = $this->getUser();

    $formPersonnalSettings = $this->createForm(PersonnalSettingsType::class, $user);

    if ($request->isMethod('POST')) {
        if ($request->request->has('personnal_settings')) {
            if ($formPersonnalSettings->isSubmitted() && $formPersonnalSettings->isValid()) {
                $user->setFirstname($request->request->get('personnal_settings')['firstname']);
                $user->setLastname($request->request->get('personnal_settings')['lastname']);

                $em = $this->getDoctrine()->getManager();
                $em->persist($user);
                $em->flush();
                $this->addFlash('personnal_success', 'Vos informations personnels ont bien été enregistrées !');
                return $this->redirectToRoute('user_profile');
            }
        }

Is that a good method? should I handle everything with ajax ? Thanks for your time !

How to branch off of an rxjs stream conditionally?

$
0
0

I am trying to simulate the "brush" feature like the one in any image editor.

I have the following streams:

  • $pointerDown: pointer pressed down
  • $pointerUp: pointer pressed up
  • $position: position of the brush
  • $escape: Escape key pressed

What I want to do

When the user is dragging the mouse, do temporary calculations. If the mouse is up, then commit those changes. If the escape key is pressed then do not commit those changes.

What I am currently handling is the first case:

$pointerDown.pipe(
   r.switchMap(() =>
       $position.pipe(
           r.throttleTime(150),
           r.map(getNodesUnderBrush),
           r.tap(prepareChanges),
           r.takeUntil($pointerUp),
           r.finalize(commitBrushStroke))
)).subscribe()

How can I end the stream in two different ways? What is the idiomatic rxjs for this?

Thanks

Sorting an array based on multiple values

$
0
0

I am trying to sort the below array, based on multiple values, report_yr and report_qtr, the array should be sorted according to year first and then as per quarter(for that same year).

// input array

let arr = [{
  report_yr: '2008',
  report_qtr: '1'
},
{
  report_yr: '2019',
  report_qtr: '3'
},
{
  report_yr: '2019',
  report_qtr: '4'
},
{
  report_yr: '2017',
  report_qtr: '2'
},
{ report_yr: '2008',
  report_qtr: '2'
}];

// expected output:

[ 
{ report_yr: '2019',
report_qtr: '4' },
{ report_yr: '2019',
report_qtr: '3' },
{ report_yr: '2008',
report_qtr: '1'
},{ report_yr: '2008',
report_qtr: '2'
},
{ report_yr: '2017',
report_qtr: '2' } ];

// What I am trying:

I am trying to use loadash methods for this,

_.sortBy(arr,
      ['report_yr', 'report_qtr']);

Similarly tried with orderBy but no luck so far.

removing hash in a specific page in vue

$
0
0

My task is similar to this Vue router, remove hash on some pages I have to set the hash mode for all but one page: mysite.com/success. User is redirected to this page from a external site. in this external site installed a redirect to mysite.com/success without #. If I set the history mode will show 404 error. To do this, you need to configure the server. I do not have access to the server. Any suggestions

Prime Number Check Javascript

$
0
0

So I mede the prime number generator in JavaScript:

function prime(from, to) {
        for (var i = from; i <= to; i++) {
            var IsPrime = false;
            for (var j = from; j < i; j++) {
                if (i % j == 0) {
                    IsPrime = true;
                }
            }
            if (IsPrime == false) {
                console.log([i]);
            }
        }
    }

    prime(2, 9999);

But the output looks like this...

[2]
[3]
[5]
[7]
[11]
...

...and I want it to look like this:

[2,3,5,7,11...]

thanks for your ideas;-)


Call of a javascript function in html body

$
0
0

I try to print a link + linkName if the linkName is not empty, I am new to JS and I don't know why it doesn't print. Both the link Name and link are not empty, as I can print them in my HTML code. The point is that I am not sure how to call the functions, here is my code:

myFile.html

...
        <p><span class="label" id ="link4">
            <script type="text/javascript">
                printLink(@product.link4Name, @product.link4);
            </script>
        </span></p>

<script type="text/javascript">

    function isEmpty(str) {
            if (typeof str == 'undefined' || !str || str.length === 0 || str === "" || !/[^\s]/.test(str) || /^\s*$/.test(str) || str.replace(/\s/g,"") === "")
                return true;
             return false;
    }

    function printLink(linkName, link) {
        if(!isEmpty(linkName))
            document.write(linkName.concat(" : ").concat(link));
    }


</script>

How to use display: block on RWD

$
0
0

I've following design on the desktop here

I want display those divs in display: block when resolution is mobile but it doesn't not work.

This is HTML code:

<body class="body light-theme">
    <section class="header col01">
        <div class="header__center">
            <div class="header__bussword-row">
                <h1 class="bussword">Dostępne reflinki</h1>
            </div>
            <div class="skins-row row02">
                <div class="ref-wrap wrap01">
                    <img src="CrQS7tw.png" class="reflink-logo">
                    <div class="reflink-info col-003">
                        <p class="reflink__link">
                            <a href="">g4skins.com</a>
                        </p>
                        <h5 class="reflink__code">Kod: xgleba</h5>
                        <p class="reflink__price">Free 0.5$</p>
                    </div>
                </div>
            </div>
            <div class="skins-row row02">
                <div class="ref-wrap wrap01">
                    <img src="CrQS7tw.png" class="reflink-logo">
                    <div class="reflink-info col-003">
                        <p class="reflink__link">
                            <a href="">g4skins.com</a>
                        </p>
                        <h5 class="reflink__code">Kod: xgleba</h5>
                        <p class="reflink__price">Free 0.5$</p>
                    </div>
                </div>
            </div>
            <div class="skins-row row02">
                <div class="ref-wrap wrap01">
                    <img src="CrQS7tw.png" class="reflink-logo">
                    <div class="reflink-info col-003">
                        <p class="reflink__link">
                            <a href="">g4skins.com</a>
                        </p>
                        <h5 class="reflink__code">Kod: xgleba</h5>
                        <p class="reflink__price">Free 0.5$</p>
                    </div>
                </div>
            </div>
            <div class="skins-row row02">
                <div class="ref-wrap wrap01">
                    <img src="CrQS7tw.png" class="reflink-logo">
                    <div class="reflink-info col-003">
                        <p class="reflink__link">
                            <a href="">g4skins.com</a>
                        </p>
                        <h5 class="reflink__code">Kod: xgleba</h5>
                        <p class="reflink__price">Free 0.5$</p>
                    </div>
                </div>
            </div>
            <div class="skins-row row02">
                <div class="ref-wrap wrap01">
                    <img src="CrQS7tw.png" class="reflink-logo">
                    <div class="reflink-info col-003">
                        <p class="reflink__link">
                            <a href="">g4skins.com</a>
                        </p>
                        <h5 class="reflink__code">Kod: xgleba</h5>
                        <p class="reflink__price">Free 0.5$</p>
                    </div>
                </div>
            </div>

    .header {
  width: 100%;
  height: 700px;
  margin: auto;
  background-image: url("../ta3.jpg");
  background-size: 70%;
  background-repeat: no-repeat;
  background-position: top right;
}

.header .header__center {
  width: 90%;
  height: 100%;
  margin: auto;
  position: relative;
  display: flex;
}

.header .header__center .header__bussword-row {
  width: 100%;
  height: auto;
  text-align: center;
  position: absolute;
  left: 0;
  right: 0;
  top: 150px;
}

.header .header__center .header__bussword-row .bussword {
  font-size: 45px;
  color: #353535;
  font-weight: 800;
}

.header .header__center .skins-row {
  width: 100%;
  height: 200px;
  top: 264px;
  margin-left: auto;
  margin-right: auto;
  display: flex;
  margin-top: 320px;
}

.header .header__center .skins-row .ref-wrap {
  width: 130px;
  height: 200px;
  position: absolute;
  border: 1px solid #27d0d3;
  cursor: pointer;
}

.header .header__center .skins-row .ref-wrap:hover > .reflink-logo {
  transform: scale(120%);
  transition: .4s;
}

.header .header__center .skins-row .ref-wrap:before {
  content: '';
  position: absolute;
  background: #fff;
  width: 100%;
  height: 100%;
  opacity: .7;
}

.header .header__center .skins-row .ref-wrap .reflink-logo {
  max-width:100%;
  margin: auto;
  left: 0;
  right: 0;
  top: -30px;
  position: absolute;
}

.header .header__center .skins-row .ref-wrap .reflink-info {
  width: 100%;
  height: 100px;
  position: absolute;
  bottom: 0;
  text-align: center;
}

.header .header__center .skins-row .ref-wrap .reflink-info .reflink__link a {
  text-decoration: none;
  font-weight: 400;
  color: #252525;
}

.header .header__center .skins-row .ref-wrap .reflink-info .reflink__code {
  padding-top: 7px;
}

.header .header__center .skins-row .ref-wrap .reflink-info .reflink__price {
  padding-top: 7px;
}

@media screen and (max-width: 400px) {
  .header {
    width: 100%;
    height: 900px;
    margin: auto;
    background-image: url("../ta3.jpg");
    background-size: 140%;
    background-repeat: no-repeat;
    background-position: top right;
  }


  .header .header__center .skins-row {
    margin-top: 20px;
  }
}

I tried add display: block to the skins-row class but it still does not work.

I tried add display: block to the skins-row class but it still does not work.

I tried add display: block to the skins-row class but it still does not work.

How to reduce the size of freehand drawing like as pencil in Canvas html 5?

$
0
0

I am using Html 5 canvas. I want to reduce thickness(size or drawing line) of freehand drawing like as pencil......................................................................................

    // Variables for referencing the canvas and 2dcanvas context
    var canvas,ctx;

    // Variables to keep track of the mouse position and left-button status 
    var mouseX,mouseY,mouseDown=0;

    // Variables to keep track of the touch position
    var touchX,touchY;

    // Draws a dot at a specific position on the supplied canvas name
    // Parameters are: A canvas context, the x position, the y position, the size of the dot
    function drawDot(ctx,x,y,size) {
        // Let's use black by setting RGB values to 0, and 255 alpha (completely opaque)
        r=0; g=151; b=150; a=255;

        // Select a fill style
        ctx.fillStyle = "rgba("+r+","+g+","+b+","+(a/255)+")";

        // Draw a filled circle
        ctx.beginPath();
        ctx.arc(x, y, size, 0, Math.PI*2, true); 
        ctx.closePath();
        ctx.fill();
    } 

    // Clear the canvas context using the canvas width and height
    function clearCanvas(canvas,ctx) {
        ctx.clearRect(0, 0, canvas.width, canvas.height);
    }

    // Keep track of the mouse button being pressed and draw a dot at current location
    function sketchpad_mouseDown() {
        mouseDown=1;
        drawDot(ctx,mouseX,mouseY,12);
    }

    // Keep track of the mouse button being released
    function sketchpad_mouseUp() {
        mouseDown=0;
    }

    // Keep track of the mouse position and draw a dot if mouse button is currently pressed
    function sketchpad_mouseMove(e) { 
        // Update the mouse co-ordinates when moved
        getMousePos(e);

        // Draw a dot if the mouse button is currently being pressed
        if (mouseDown==1) {
            drawDot(ctx,mouseX,mouseY,12);
        }
    }

    // Get the current mouse position relative to the top-left of the canvas
    function getMousePos(e) {
        if (!e)
            var e = event;

        if (e.offsetX) {
            mouseX = e.offsetX;
            mouseY = e.offsetY;
        }
        else if (e.layerX) {
            mouseX = e.layerX;
            mouseY = e.layerY;
        }
     }

    // Draw something when a touch start is detected
    function sketchpad_touchStart() {
        // Update the touch co-ordinates
        getTouchPos();

        drawDot(ctx,touchX,touchY,12);

        // Prevents an additional mousedown event being triggered
        event.preventDefault();
    }

    // Draw something and prevent the default scrolling when touch movement is detected
    function sketchpad_touchMove(e) { 
        // Update the touch co-ordinates
        getTouchPos(e);

        // During a touchmove event, unlike a mousemove event, we don't need to check if the touch is engaged, since there will always be contact with the screen by definition.
        drawDot(ctx,touchX,touchY,12); 

        // Prevent a scrolling action as a result of this touchmove triggering.
        event.preventDefault();
    }

    // Get the touch position relative to the top-left of the canvas
    // When we get the raw values of pageX and pageY below, they take into account the scrolling on the page
    // but not the position relative to our target div. We'll adjust them using "target.offsetLeft" and
    // "target.offsetTop" to get the correct values in relation to the top left of the canvas.
    function getTouchPos(e) {
        if (!e)
            var e = event;

        if(e.touches) {
            if (e.touches.length == 1) { // Only deal with one finger
                var touch = e.touches[0]; // Get the information for finger #1
                touchX=touch.pageX-touch.target.offsetLeft;
                touchY=touch.pageY-touch.target.offsetTop;
            }
        }
    }


    // Set-up the canvas and add our event handlers after the page has loaded
    function init() {
        // Get the specific canvas element from the HTML document
        canvas = document.getElementById('sketchpad');

        // If the browser supports the canvas tag, get the 2d drawing context for this canvas
        if (canvas.getContext)
            ctx = canvas.getContext('2d');

        // Check that we have a valid context to draw on/with before adding event handlers
        if (ctx) {
            // React to mouse events on the canvas, and mouseup on the entire document
            canvas.addEventListener('mousedown', sketchpad_mouseDown, false);
            canvas.addEventListener('mousemove', sketchpad_mouseMove, false);
            window.addEventListener('mouseup', sketchpad_mouseUp, false);

            // React to touch events on the canvas
            canvas.addEventListener('touchstart', sketchpad_touchStart, false);
            canvas.addEventListener('touchmove', sketchpad_touchMove, false);
        }
    }
#sketchpadapp {
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    -khtml-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
}
.leftside {
    float:left;
    width:220px;
    height:285px;
    padding:10px;
    border-radius:4px;
}
.rightside {
    float:left;
    margin-left:10px;
}
#sketchpad {
    float:left;
    height:300px;
    width:400px;
    border:2px solid #888;
    border-radius:4px;
    position:relative; 
}
#clearbutton {
    font-size: 15px;
    padding: 10px;
    -webkit-appearance: none;
    background: #eee;
    border: 1px solid #888;
}
<body onload="init()"><div id="sketchpadapp"><div class="leftside"><input type="submit" value="Clear Sketchpad" id="clearbutton" onclick="clearCanvas(canvas,ctx);"></div><div class="rightside"><canvas id="sketchpad" height="300" width="400"></canvas></div></div></body>

I am using Html 5 canvas. I want to reduce thickness(size or drawing line) of freehand drawing like as pencil.

How to use existing HTML files in React Native

$
0
0

I have designed my app using HTML and CSS. I’d like to “copy” it over to React-Native and keep all the formatting and styling. Is there a tool or best-practices method when doing something like this? I have tried rendering Raw HTML with packages like react-native-html5 - https://www.npmjs.com/package/react-native-html5, react-native-render-html - https://github.com/archriss/react-native-render-html, webview - https://reactnative.dev/docs/webview but none makes the view interactive.

My RawHTML look like this

<html>
 <body>
  <h2>HTML Forms</h2>
  <form>
  <label for="fname">First name:</label><br>
  <input type="text" id="fname" name="fname" value="FristName"><br>
  <label for="lname">Last name:</label><br>
  <input type="text" id="lname" name="lname" value="LastName"><br><br>
  <input type="submit" value="Submit">
  </form> 
</body>

aliases not working while using Storybook/vue

$
0
0

I'm using Storybook for Vue and I'm trying to add aliases to the webpack config in storybook/main.js:

  resolve: {
    alias: {
      'vue$': 'vue/dist/vue.esm.js',
      '@': path.resolve('src'),
        '@': 'src',
      '@src': 'src'
    },
    extensions: ['*', '.js', '.vue', '.json']
  },

This is how my file structure looks:

enter image description here

And the error I'm getting:

npm run storybook
    > scss-loader-example@0.1.0 storybook /Users/test/Documents/webdev/test/scss-loader-example
    > start-storybook -p 6006

    info @storybook/vue v5.3.17
    info
    info => Loading presets
    info => Loading presets
    info => Adding stories defined in ".storybook/main.js".
    info => Using default Webpack setup.
    webpack built c29ceda255d3976f13b9 in 9398ms
    ✖ 「wdm」: Hash: c29ceda255d3976f13b9
    Version: webpack 4.42.0
    Time: 9398ms
    Built at: 2020-03-18 11:41:13
                                              Asset      Size        Chunks                                Chunk Names
                                        iframe.html  2.87 KiB                [emitted]
                main.c29ceda255d3976f13b9.bundle.js   321 KiB          main  [emitted] [immutable]  [big]  main
            main.c29ceda255d3976f13b9.bundle.js.map   213 KiB          main  [emitted] [dev]               main
        runtime~main.c29ceda255d3976f13b9.bundle.js  31.2 KiB  runtime~main  [emitted] [immutable]         runtime~main
    runtime~main.c29ceda255d3976f13b9.bundle.js.map  32.3 KiB  runtime~main  [emitted] [dev]               runtime~main
        vendors~main.c29ceda255d3976f13b9.bundle.js  2.68 MiB  vendors~main  [emitted] [immutable]  [big]  vendors~main
    vendors~main.c29ceda255d3976f13b9.bundle.js.map  2.79 MiB  vendors~main  [emitted] [dev]               vendors~main
    Entrypoint main [big] = runtime~main.c29ceda255d3976f13b9.bundle.js runtime~main.c29ceda255d3976f13b9.bundle.js.map vendors~main.c29ceda255d3976f13b9.bundle.js vendors~main.c29ceda255d3976f13b9.bundle.js.map main.c29ceda255d3976f13b9.bundle.js main.c29ceda255d3976f13b9.bundle.js.map
    [0] multi ./node_modules/@storybook/core/dist/server/common/polyfills.js ./node_modules/@storybook/core/dist/server/preview/globals.js ./.storybook/generated-entry.js (webpack)-hot-middleware/client.js?reload=true&quiet=true 64 bytes {main} [built]
    [./.storybook/generated-entry.js] 230 bytes {main} [built]
    [./node_modules/@storybook/core/dist/server/common/polyfills.js] 120 bytes {vendors~main} [built]
    [./node_modules/@storybook/core/dist/server/preview/globals.js] 93 bytes {vendors~main} [built]
    [./node_modules/@storybook/vue/dist/client/index.js] 1.21 KiB {vendors~main} [built]
    [./node_modules/airbnb-js-shims/index.js] 40 bytes {vendors~main} [built]
    [./node_modules/core-js/features/symbol/index.js] 359 bytes {vendors~main} [built]
    [./node_modules/global/window.js] 232 bytes {vendors~main} [built]
    [./node_modules/querystring-es3/index.js] 127 bytes {vendors~main} [built]
    [./node_modules/regenerator-runtime/runtime.js] 23.6 KiB {vendors~main} [built]
    [./node_modules/webpack-hot-middleware/client-overlay.js] (webpack)-hot-middleware/client-overlay.js 2.17 KiB {vendors~main} [built]
    [./node_modules/webpack-hot-middleware/client.js?reload=true&quiet=true] (webpack)-hot-middleware/client.js?reload=true&quiet=true 7.68 KiB {vendors~main} [built]
    [./node_modules/webpack-hot-middleware/node_modules/strip-ansi/index.js] (webpack)-hot-middleware/node_modules/strip-ansi/index.js 161 bytes {vendors~main} [built]
    [./node_modules/webpack-hot-middleware/process-update.js] (webpack)-hot-middleware/process-update.js 4.35 KiB {vendors~main} [built]
    [./node_modules/webpack/buildin/harmony-module.js] (webpack)/buildin/harmony-module.js 573 bytes {vendors~main} [built]
        + 708 hidden modules

    ERROR in ./src/components/Balance.vue?vue&type=script&lang=js& (./node_modules/babel-loader/lib??ref--0-0!./node_modules/vue-loader/lib??vue-loader-options!./src/components/Balance.vue?vue&type=script&lang=js&)
    Module not found: Error: Can't resolve '@/js/automation-const' in '/Users/test/Documents/webdev/test/scss-loader-example/src/components'
     @ ./src/components/Balance.vue?vue&type=script&lang=js& (./node_modules/babel-loader/lib??ref--0-0!./node_modules/vue-loader/lib??vue-loader-options!./src/components/Balance.vue?vue&type=script&lang=js&) 27:0-56 53:13-32
     @ ./src/components/Balance.vue?vue&type=script&lang=js&
     @ ./src/components/Balance.vue
     @ ./stories/1-Button.stories.js
     @ ./stories sync ^\.\/(?:(?:(?!\.)(?:(?:(?!(?:|\/)\.).)*?)\/)?(?!\.)(?=.)[^\/]*?\.stories\.js\/?)$
     @ ./.storybook/generated-entry.js
     @ multi ./node_modules/@storybook/core/dist/server/common/polyfills.js ./node_modules/@storybook/core/dist/server/preview/globals.js ./.storybook/generated-entry.js (webpack)-hot-middleware/client.js?reload=true&quiet=true

    ERROR in ./src/components/Balance.vue?vue&type=script&lang=js& (./node_modules/babel-loader/lib??ref--0-0!./node_modules/vue-loader/lib??vue-loader-options!./src/components/Balance.vue?vue&type=script&lang=js&)
    Module not found: Error: Can't resolve '@/js/utils/helper' in '/Users/test/Documents/webdev/test/scss-loader-example/src/components'
     @ ./src/components/Balance.vue?vue&type=script&lang=js& (./node_modules/babel-loader/lib??ref--0-0!./node_modules/vue-loader/lib??vue-loader-options!./src/components/Balance.vue?vue&type=script&lang=js&) 26:0-39 57:19-25
     @ ./src/components/Balance.vue?vue&type=script&lang=js&
     @ ./src/components/Balance.vue
     @ ./stories/1-Button.stories.js
     @ ./stories sync ^\.\/(?:(?:(?!\.)(?:(?:(?!(?:|\/)\.).)*?)\/)?(?!\.)(?=.)[^\/]*?\.stories\.js\/?)$
     @ ./.storybook/generated-entry.js
     @ multi ./node_modules/@storybook/core/dist/server/common/polyfills.js ./node_modules/@storybook/core/dist/server/preview/globals.js ./.storybook/generated-entry.js (webpack)-hot-middleware/client.js?reload=true&quiet=true
    Child HtmlWebpackCompiler:
                              Asset     Size               Chunks  Chunk Names
        __child-HtmlWebpackPlugin_0  6.5 KiB  HtmlWebpackPlugin_0  HtmlWebpackPlugin_0
        Entrypoint HtmlWebpackPlugin_0 = __child-HtmlWebpackPlugin_0
        [./node_modules/@storybook/core/node_modules/html-webpack-plugin/lib/loader.js!./node_modules/@storybook/core/dist/server/templates/index.ejs] 2.15 KiB {HtmlWebpackPlugin_0} [built]

    WARN Broken build, fix the error above.
    WARN You may need to refresh the browser.

And the paths inside Balance.vue which are causing the issue:

import helper from '@/js/utils/helper'
import automationConstants from '@/js/automation-const'

Any ideas what I'm doing wrong?

Viewing all 142382 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>