Troubleshooting FabricJS: Object manipulation is disabled until a common selection is made

I am currently in the process of developing a product configurator with Vue and FabricJS.

To set up my canvas, I used

this.canvas = new fabric.Canvas("canvas");
<template>
  <div id="wrapper">
    <div id="left"></div>
    <canvas id="canvas"/>
  </div>
</template>

However, after adding an object to the canvas (IText, Textbox, Image) and selecting it with the mouse, I encountered difficulties using the object controls for resizing, scaling, skewing, or rotating the object. Although I was able to move the object on the canvas, the controls did not respond as expected. Interestingly, after adding another object, selecting both at once, and then deselecting them, the controls began working properly. This issue did not occur when testing on JsFiddle, where everything functioned correctly.

Controls not working until both objects are selected

I experienced this problem across different web browsers.

Could it be that I missed including a specific canvas property that enables control functionality immediately after adding an object? Or is there possibly a bug in Fabric.js causing this issue?

Answer №1

After encountering some issues, I came up with a creative solution: I devised a workaround by inserting an invisible helper object onto the canvas immediately after its creation. Then, for each new object added, I used programming to select and deselect all objects in order to ensure proper behavior. While I understand that this method may be considered a "hack," it effectively resolves the issue at hand :)

this.canvas = new fabric.Canvas("canvas", {
    ...canvasProps
});

const helperObj = new fabric.Object({});    //invisible abstract object
helperObj.set("selectable", false);         //preventing manual selection and modification
this.canvas.add(helperObj);

this.canvas.on("object:added", () => {
  //workaround - selecting all objects to enable object controls

  let objects = this.canvas.getObjects();
  var selection = new fabric.ActiveSelection(objects, {
     canvas: this.canvas,
  });
  this.canvas.setActiveObject(selection);   //selecting all objects...
  this.canvas.discardActiveObject();        //...and then deselecting them
  this.canvas.requestRenderAll();
});

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

I can't seem to figure out why the game is not showing up on the desktop in this index HTML

I have come across a game online and I am trying to run it from my desktop. Do I need to do anything special with the URLs or images to ensure that the file recognizes where everything is located? I have all the files and .png images in one folder at the s ...

Problem with memory management in ThreeJS

After developing a ThreeJS app using the canvas renderer to meet project requirements, I encountered a memory and garbage collection issue. As part of the application logic, numerous meshes are created for animations on sections of a flat 2D donut or ring ...

ng-repeat unable to function within a textarea

Could you help me troubleshoot why the ng-repeat is not functioning properly within a textarea? Oddly enough, it works fine when moved outside of the textarea. <textarea> <style ng-repeat="entry in bgTakeoverSettings.breakPoints"> ...

Issue with sync-request when using post data doesn't seem to be functioning

I am currently working on a Node.js application where I need to make synchronous requests. After some research, I came across the sync-request npm package for making these requests. However, when I tried using the code below, I encountered an error with th ...

What is the best way to connect my Vue components with the active record objects in my Rails application?

Within a Rails project with Vue on the front-end, all views are powered by Vue while routing and models adhere to the Rails MVC pattern. Incorporating objects from Active Record into a Vue component is a goal. Additionally, there is a desire to create a V ...

Retrieve the rendered component color variables exclusively from the global color variable file

color_variables.css: [data-theme='default'] { --avatar_bg: #000; --avatar_text: #fff; --avatar_border: red; --button_bg: blue; --button_text: #fff; --button_border: darkblue; --modal_widget_bg: orange; --footer_bg: yellow; --foo ...

Caution: The React Hook useEffect is missing a required dependency

What is the best way to eliminate the warning "React Hook useEffect has a missing dependency" while developing my code? Here is a snippet of the code that triggers the warning: useEffect(() => { if(inactive){ document.querySelect ...

Is there a way to delete specific information from a JSON response?

Received the service response in the following format: Temp([ { XXX: "2", YYY: "3", ZZZ: "4" }, { XXX: "5", YYY: "6", ZZZ: "7" }, { XXX: "1", YYY: "2", ZZZ: "3" } ]); I need to manipulate this response in J ...

The Enigma of AngularJS Coding

Check out this code snippet. $scope.$watch('year', reloadData); $scope.$watch('month', reloadData); $scope.year = 2017; $scope.month = 1; var reloadData = function() { /* Refresh Data */ } var init = function() { $scope.year ...

Angular JS Unveiled: Deciphering HTML Entities

I'm looking for a solution to decode HTML entities in text using AngularJS. Here is the string I have: "&quot;12.10 On-Going Submission of &quot;&quot;Made Up&quot;&quot; Samples.&quot;" I need to find a way to decode this u ...

Tips for including type definitions when adding elements to an array in TypeScript

Having trouble avoiding the use of 'any' as the type definition when pushing elements into an array? I attempted to specify the type but encountered an error. Here is a snippet of the code: interface answerProps { state: string; answer: s ...

JavaScript is unable to bring in an npm module

Having trouble importing an npm module using import fs from 'fs'; in my main.js file that is linked with index.html. The script tag connecting the JS file has the attribute type="module". However, the browser console shows the error: Un ...

The combination of the card hover effect and the bootstrap modal creates complications

Hey there! I'm in the midst of crafting a webpage using Bootstrap and EJS. My aim is to craft a modal window that pops up when a specific button is clicked to display extra information, and upon clicking an X or "close" button, the modal should disapp ...

Issue with implementing setCallBack for updating variant prices in Shopify

I'm currently attempting to update the price of a product when a variant is chosen. I've tried implementing the following code, but haven't been successful in getting it to function properly. The script has been added to the theme.liquid fi ...

Expand or collapse level 1 nodes with v-treeview component

I have created a special button in my tree view that has the ability to toggle open and close all nodes within it. The button code: <v-btn @click="toggleTreeview" /> Here is my v-tree markup: <v-treeview :value="x" @inpu ...

Try utilizing a single Associative Array instead of managing two separate index arrays when working in jQuery

Fiddle Example I've created a function that retrieves the next nearest number and its corresponding color based on a given value. For example, if the input is 500, the function will return 600 with the color beige. Currently, I'm using two separ ...

In the React js and emotion framework, fonts are only loaded in production mode after the page has been re

I have set up emotion's Global component to globally apply a font to my app: export const GlobalStyle: FC<{}> = () => ( <Global styles={css` @import url('https://fonts.googleapis.com/css2?family=Poppins:wght@100;300;400;50 ...

Contrasting WebSQL and SQLite in terms of their utility in mobile applications and web browsers

Could you confirm if WebSQL and SQLite are the same? Are both WebSQL and SQLite available in PhoneGap? Will the JavaScript code used for WebSQL in a web browser be the same for a mobile app, or will we need different code? What advantages does WebSQL ha ...

Is there a way to verify the existence of an element based on its class name?

In the title of my question, I mentioned that my element lacks an id attribute. So how can I determine if it exists or not? Here is the HTML code: <div class="classname">something</div> Note1: If there was an id attribute like this: var el ...

Removing duplicate elements from an array using lodash

What is the best way to remove duplicate values from an array? var numbers = [1, 1, 5, 5, 4, 9]; I want my result to be: var numbers = [4, 9]; Is there a method in lodash that can help me achieve this? ...