According to the Estatuto de Trabajadores, art. 21.4 an employer can put a permanency clause in your work contract if he or she has paid for a specific training course for you. Either to start up specific projects or to be able to meet certain job requisites, for a maximum time 2 years. The clause can state that if you leave before that time has passed, you will pay your employer indemnization, usually the cost of the course.
With regards to the cost of the course, it would be good to know beforehand what those were and whether they were 100% out of pocket for your employer, or a course that was heavily subsidised by the Seguridad Social, like ´prevención de riesgos´ courses, as those are paid out of a percentage of your wages that your employer pays for you in your name to the Seguridad Social.